From dbc53a555e64fdd0b848bf33b4208820b8701509 Mon Sep 17 00:00:00 2001 From: Parker Date: Wed, 13 Nov 2024 22:45:57 -0600 Subject: Update UI --- app/src/components/Dashboard.tsx | 42 ++++++++++++++------ app/src/components/Login.tsx | 66 ++++++++++++++----------------- app/src/components/Navbar.tsx | 56 +++++++++++++++++++++++---- app/src/components/Signup.tsx | 84 +++++++++++++++++++--------------------- 4 files changed, 149 insertions(+), 99 deletions(-) (limited to 'app/src/components') diff --git a/app/src/components/Dashboard.tsx b/app/src/components/Dashboard.tsx index e16c44e..f3442e0 100644 --- a/app/src/components/Dashboard.tsx +++ b/app/src/components/Dashboard.tsx @@ -47,10 +47,7 @@ function Dashboard() { .catch((error: unknown) => { if (axios.isAxiosError(error)) { - if (error.response?.status === 404) { - // Create a message alerting the user there are no links - navigate('/login'); - } else { + if (error.response?.status != 404) { navigate('/login'); } } @@ -68,11 +65,12 @@ function Dashboard() { navigate('/login'); } }) - - // Catch 404 error = user has no logs - - .catch(() => { - navigate('/login'); + .catch((error: unknown) => { + if (axios.isAxiosError(error)) { + if (error.response?.status != 404) { + navigate('/login'); + } + } }); }, []); @@ -117,7 +115,7 @@ function Dashboard() { return ( <> - +
@@ -127,6 +125,17 @@ function Dashboard() { + {/* If there are no links, put a special message */} + {links.length === 0 && ( + + + + )} + {/* For every link and its logs */} {links.map((link) => ( @@ -161,7 +170,7 @@ function Dashboard() { - {/* Render logs only if visibleLog matches the link */} + {/* Render all logs for the link */} {logs .filter((log) => log.link === link.link) .map((log, index, filteredLogs) => ( @@ -181,6 +190,17 @@ function Dashboard() { ))} + {/* If the link has no logs, put a special message */} + {logs.filter((log) => log.link === link.link).length === + 0 && ( + + + + )}
Link
+
+ You do not have any shortened links - try creating one. +
+
+
+ No logs for this link +
+
diff --git a/app/src/components/Login.tsx b/app/src/components/Login.tsx index 807face..badb5b1 100644 --- a/app/src/components/Login.tsx +++ b/app/src/components/Login.tsx @@ -1,5 +1,5 @@ import { useState, FormEvent } from 'react'; -import styles from '../styles/Login.module.css'; +import styles from '../styles/Auth.module.css'; import { Link } from 'react-router-dom'; import { useNavigate } from 'react-router-dom'; import axios from 'axios'; @@ -51,42 +51,36 @@ function Login() { return ( <> -
-

Log In

-

- {error} +

+

Log In

+

{error}

+
+
+ setUsername(e.target.value)} + required + /> + setPassword(e.target.value)} + required + /> + +
+
+

+ Don't have an account?{' '} + + Create one now +

-
-
-
-
- setUsername(e.target.value)} - required - /> - setPassword(e.target.value)} - required - /> - -
-
-

- Don't have an account?{' '} - - Create one now - -

-
-
); diff --git a/app/src/components/Navbar.tsx b/app/src/components/Navbar.tsx index 5107bf4..53c1f52 100644 --- a/app/src/components/Navbar.tsx +++ b/app/src/components/Navbar.tsx @@ -1,21 +1,63 @@ +import { useState, useEffect } from 'react'; import styles from '../styles/Navbar.module.css'; import { Link } from 'react-router-dom'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faCircleUp, faCircleDown } from '@fortawesome/free-solid-svg-icons'; function Navbar() { + const [isOnline, setIsOnline] = useState(null); + + useEffect(() => { + const checkAPIStatus = async () => { + try { + const res = await fetch('/api/ping'); + + if (res.status === 200) { + setIsOnline(true); + } else { + setIsOnline(false); + } + } catch (error) { + setIsOnline(false); + } + }; + + checkAPIStatus(); + }); + return (
-
+ - ); diff --git a/app/src/components/Signup.tsx b/app/src/components/Signup.tsx index 5ec2e17..f4a3368 100644 --- a/app/src/components/Signup.tsx +++ b/app/src/components/Signup.tsx @@ -1,5 +1,5 @@ import { useState, FormEvent } from 'react'; -import styles from '../styles/Login.module.css'; +import styles from '../styles/Auth.module.css'; import { Link } from 'react-router-dom'; import { useNavigate } from 'react-router-dom'; import axios from 'axios'; @@ -64,51 +64,45 @@ function Signup() { return ( <> -
-

Sign up

-

- {error} +

+

Sign up

+

{error}

+
+
+ setUsername(e.target.value)} + required + /> + setPassword(e.target.value)} + required + /> + setPasswordConfirm(e.target.value)} + required + /> + +
+
+

+ Already have an account?{' '} + + Log in here. +

-
-
-
-
- setUsername(e.target.value)} - required - /> - setPassword(e.target.value)} - required - /> - setPasswordConfirm(e.target.value)} - required - /> - -
-
-

- Already have an account?{' '} - - Log in here. - -

-
-
); -- cgit v1.2.3-70-g09d2