Skip to content

Commit c0dfcb2

Browse files
committed
refactor: basic URL validation, better frontend docs
1 parent ee2c04a commit c0dfcb2

File tree

5 files changed

+55
-10
lines changed

5 files changed

+55
-10
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
### Best Practices
1010

11-
- We use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for our commit messages. This methodology ensures uniformity, clarity, and ease of understanding for all contributors.
11+
- We use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for our commit messages for uniformity and clarity.
1212
- Make sure to write tests for the most complex parts of your code.
1313
- For manual API testing, include screenshots from Postman.
1414
- Go uses **TitleCase** and React Native uses **camelCase** for naming conventions.

docs/FRONTEND-SETUP.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/frontend.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
### Frontend Setup
2+
3+
**Please set up the backend before proceeding.**
4+
5+
### Configure Environment Variables
6+
```shell
7+
# Make an .env file in the frontend directory using the template in .env.example.
8+
cd frontend && cp ../.env.example .env
9+
10+
# Configure your environment variables in your IDE or using a command line text editor.
11+
vim .env
12+
```
13+
14+
### Enter the Development Environment
15+
```shell
16+
# Enter the development environment in the root directory.
17+
cd ../ && nix develop --impure
18+
```
19+
20+
### Install Frontend Dependencies
21+
```shell
22+
# Use bun to install frontend dependencies.
23+
cd frontend && bun install
24+
```
25+
26+
### Ensure the backend is running
27+
```shell
28+
# Create *another terminal window* and run the following:
29+
backend-run
30+
```
31+
32+
### Run the frontend
33+
```shell
34+
frontend run
35+
```
36+
37+
Finally, you can scan the QR code with the Expo Go app installed to view a development build with hot reloading.
38+
You can also use iOS/Android simulators to simulate & test the app on your computer.

frontend/bun.lockb

0 Bytes
Binary file not shown.

frontend/components/ExternalLink.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import { Link } from "expo-router";
22
import { openBrowserAsync } from "expo-web-browser";
33
import { type ComponentProps } from "react";
4-
import { Platform } from "react-native";
4+
import { Platform, Alert } from "react-native";
55

66
type Props = Omit<ComponentProps<typeof Link>, "href"> & { href: string | any };
77

8+
function isValidUrl(url: string): boolean {
9+
try {
10+
new URL(url);
11+
return true;
12+
} catch {
13+
return false;
14+
}
15+
}
16+
817
export function ExternalLink({ href, ...rest }: Props) {
918
return (
1019
<Link
@@ -13,9 +22,13 @@ export function ExternalLink({ href, ...rest }: Props) {
1322
href={href}
1423
onPress={async (event) => {
1524
if (Platform.OS !== "web") {
16-
// Prevent the default behavior of linking to the default browser on native.
1725
event.preventDefault();
18-
// Open the link in an in-app browser.
26+
27+
if (!isValidUrl(href)) {
28+
Alert.alert("Invalid URL", "An invalid URL was provided.");
29+
return;
30+
}
31+
1932
await openBrowserAsync(href);
2033
}
2134
}}

0 commit comments

Comments
 (0)