diff --git a/package-lock.json b/package-lock.json index ed651b7..5eff25e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "react": "^18.2.0", "react-bootstrap": "^2.10.2", "react-dom": "^18.2.0", - "react-router-dom": "^6.22.3", + "react-router-dom": "^6.23.0", "react-tiles-dnd": "^0.1.2", "recharts": "^2.12.5", "sass": "^1.72.0" @@ -1815,9 +1815,9 @@ } }, "node_modules/@remix-run/router": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.15.3.tgz", - "integrity": "sha512-Oy8rmScVrVxWZVOpEF57ovlnhpZ8CCPlnIIumVcV9nFdiSIrus99+Lw78ekXyGvVDlIsFJbSfmSovJUhCWYV3w==", + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.16.0.tgz", + "integrity": "sha512-Quz1KOffeEf/zwkCBM3kBtH4ZoZ+pT3xIXBG4PPW/XFtDP7EGhtTiC2+gpL9GnR7+Qdet5Oa6cYSvwKYg6kN9Q==", "engines": { "node": ">=14.0.0" } @@ -6035,11 +6035,11 @@ "integrity": "sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==" }, "node_modules/react-router": { - "version": "6.22.3", - "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.22.3.tgz", - "integrity": "sha512-dr2eb3Mj5zK2YISHK++foM9w4eBnO23eKnZEDs7c880P6oKbrjz/Svg9+nxqtHQK+oMW4OtjZca0RqPglXxguQ==", + "version": "6.23.0", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.23.0.tgz", + "integrity": "sha512-wPMZ8S2TuPadH0sF5irFGjkNLIcRvOSaEe7v+JER8508dyJumm6XZB1u5kztlX0RVq6AzRVndzqcUh6sFIauzA==", "dependencies": { - "@remix-run/router": "1.15.3" + "@remix-run/router": "1.16.0" }, "engines": { "node": ">=14.0.0" @@ -6049,12 +6049,12 @@ } }, "node_modules/react-router-dom": { - "version": "6.22.3", - "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.22.3.tgz", - "integrity": "sha512-7ZILI7HjcE+p31oQvwbokjk6OA/bnFxrhJ19n82Ex9Ph8fNAq+Hm/7KchpMGlTgWhUxRHMMCut+vEtNpWpowKw==", + "version": "6.23.0", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.23.0.tgz", + "integrity": "sha512-Q9YaSYvubwgbal2c9DJKfx6hTNoBp3iJDsl+Duva/DwxoJH+OTXkxGpql4iUK2sla/8z4RpjAm6EWx1qUDuopQ==", "dependencies": { - "@remix-run/router": "1.15.3", - "react-router": "6.22.3" + "@remix-run/router": "1.16.0", + "react-router": "6.23.0" }, "engines": { "node": ">=14.0.0" diff --git a/package.json b/package.json index 85be311..caaae65 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "react": "^18.2.0", "react-bootstrap": "^2.10.2", "react-dom": "^18.2.0", - "react-router-dom": "^6.22.3", + "react-router-dom": "^6.23.0", "react-tiles-dnd": "^0.1.2", "recharts": "^2.12.5", "sass": "^1.72.0" diff --git a/src/assets/css/Header.css b/src/assets/css/Header.css index f73c4ce..dd954d5 100644 --- a/src/assets/css/Header.css +++ b/src/assets/css/Header.css @@ -1,53 +1,53 @@ -*{ +* { box-sizing: border-box; } -body{ +body { margin: 0; } -.site-title{ +.site-title { font-size: 4rem; - } -.header-nav{ - border-left: #E4F2E7; +.header-nav { + border-left: #e4f2e7; border-left-style: solid; margin: 4rem; + width: calc(100% - 15rem); /* adjust the width of the header-nav element to make room for the logout button */ } -.header{ - background-color: #2D3E40; - color: #E4F2E7; + +.header { + background-color: #2d3e40; + color: #e4f2e7; display: flex; gap: 2rem; padding-left: 1rem; padding-right: 1rem; + position: relative; /* add this */ } - -.site-title:hover{ - color: #E4F2E7; +.site-title:hover { + color: #e4f2e7; } -.header a{ - color: #E4F2E7; +.header a { + color: #e4f2e7; text-decoration: none; - height: 100%; display: flex; align-items: center; - padding: .25rem; + padding: 0.25rem; padding-top: 1.5rem; padding-bottom: 1.5rem; } -.header-item:hover{ - color: #2D3E40; - background-color: #E4F2E7; +.header-item:hover { + color: #2d3e40; + background-color: #e4f2e7; } -.header ul{ +.header ul { padding-left: 1rem; margin: 0; list-style: none; @@ -55,7 +55,52 @@ body{ gap: 1rem; } -.header li:active{ - background-color: #E4F2E7; - color: #2D3E40; +.header li:active { + background-color: #e4f2e7; + color: #2d3e40; +} + +.logout-btn { + position: absolute; + right: 10px; + top: 50%; + transform: translateY(-50%); + font-size: 1rem; + padding: 0.25rem; + padding-top: 1.5rem; + padding-bottom: 1.5rem; + color: #e4f2e7; + background-color: transparent; + border: none; + cursor: pointer; +} + +.logout-btn:hover { + color: #2d3e40; + background-color: #e4f2e7; + height: 100%; } + +.username { + position: absolute; + right: 100px; + top: 50%; + transform: translateY(-50%); + font-size: 1rem; + padding: 0.25rem; + padding-top: 1.5rem; + padding-bottom: 1.5rem; + color: #e4f2e7; + background-color: transparent; + border: none; + cursor: pointer; +} + +.text-muted { + color: #6c757d; + pointer-events: none; +} + +.bg-transparent { + background-color: transparent; +} \ No newline at end of file diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 1daa3e5..394cd6e 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -1,35 +1,54 @@ import useWindowDimensions from "../hooks/WindowDimensionsHook.tsx"; import "../assets/css/Header.css" -import {Link} from "react-router-dom"; +import {Link, useNavigate, useLocation} from "react-router-dom"; +import {auth} from "../utils/firebase.ts"; interface Props { - user?: string + user?: string; + children?: React.ReactNode; } -export function Header({user} : Props) { - const {width, height} = useWindowDimensions(); - const aspect_ratio = (width == 0 ? 1 : width) / (height == 0 ? 1 : height); +export function Header({ user }: Props) { + const { width, height } = useWindowDimensions(); + const aspect_ratio = (width == 0? 1 : width) / (height == 0? 1 : height); const use_narrow = aspect_ratio < 0.7; - return
+ const currentUser = auth.currentUser?.displayName?? ""; - {/*App Name reloads home page*/} - -

{use_narrow ? "B-19" : "Budget-19"}

-
+ const navigate = useNavigate(); + const location = useLocation(); - {/*Pages*/} - +
+ ); } \ No newline at end of file diff --git a/src/pages/index/IndexPage.tsx b/src/pages/index/IndexPage.tsx index 1c60ae6..16e23ab 100644 --- a/src/pages/index/IndexPage.tsx +++ b/src/pages/index/IndexPage.tsx @@ -2,17 +2,31 @@ import {Header} from "../../components/Header.tsx"; import {Footer} from "../../components/Footer.tsx"; import "./IndexPage.scss" -import {Link} from "react-router-dom"; +import {Link, useNavigate} from "react-router-dom"; import { signInWithGoogle } from '../../utils/authentication'; +import { useState } from "react"; -interface Props { - user?: string +interface IndexPageProps { + user?: string; } -function IndexPage({ user }: Props) { +function IndexPage({ user }: IndexPageProps) { + const [currentUser, setCurrentUser] = useState(user); + const navigate = useNavigate(); + + const handleSignIn = async () => { + const user = await signInWithGoogle(); + setCurrentUser(user); + navigate('/dash', { replace: true }); // Redirect to /dash after signing in + }; + return (<>
-
+ {currentUser? ( +
+ ) : ( +
// or some other default value + )}
@@ -34,7 +48,7 @@ function IndexPage({ user }: Props) {

Login

-
@@ -54,4 +68,4 @@ function IndexPage({ user }: Props) { ); } -export default IndexPage +export default IndexPage; \ No newline at end of file diff --git a/src/router.tsx b/src/router.tsx index a8c8d51..92a7964 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -49,7 +49,7 @@ const tileset_many: Array<{ text: string; rows: number; cols: number }> = [ { text: "Tile 13", cols: 2, rows: 2 }, { text: "Tile 14", cols: 2, rows: 2 }, { text: "Tile 15", cols: 1, rows: 1 }, - { text: "Tile 16", cols: 1, rows: 1 }, + {text: "Tile 16", cols: 1, rows:1 }, { text: "Tile 17", cols: 1, rows: 1 }, { text: "Tile 18", cols: 1, rows: 1 }, { text: "Tile 19", cols: 2, rows: 1 }, @@ -97,7 +97,7 @@ const tileset_weird: Array<{ text: string; rows: number; cols: number }> = [ export const router = createBrowserRouter([ { path: "/", - element: , + element: , errorElement: <_404Page/> }, { @@ -114,7 +114,7 @@ export const router = createBrowserRouter([ { path: "/user-test", element: , - errorElement: <_404Page/> + errorElement:<_404Page/> }, { path: "/graphs", diff --git a/src/utils/authentication.ts b/src/utils/authentication.ts index 1834929..d175301 100644 --- a/src/utils/authentication.ts +++ b/src/utils/authentication.ts @@ -6,13 +6,16 @@ import { signInWithPopup } from "firebase/auth"; const googleProvider = new GoogleAuthProvider(); // Function to sign in with Google -export const signInWithGoogle = async () => { +export const signInWithGoogle = async (): Promise => { try { const result = await signInWithPopup(auth, googleProvider); const user = result.user; console.log(user); - // Do something with the user object (e.g. save to state) + // Return the entire user object + return user; } catch (error) { console.error(error); + // Return null if there was an error + return null; } -}; +}; \ No newline at end of file