diff --git a/app/account/page.tsx b/app/account/page.tsx index 7d68b25..5d78529 100644 --- a/app/account/page.tsx +++ b/app/account/page.tsx @@ -37,6 +37,7 @@ export default function History() { const [profileType, setProfileType] = useState("Private"); useEffect(() => { + if (!user) return; auth.onAuthStateChanged((user) => { if (user) { setSignedIn(true); @@ -55,7 +56,7 @@ export default function History() { setHighScore(doc.highScore); setLowScore(doc.lowScore); }); - }, []); + }, [user]); const [currentWindow, setCurrentWindow] = useState("stats"); @@ -92,52 +93,60 @@ export default function History() { selected={currentWindow == "account" ? true : false} /> - {currentWindow == "stats" ? ( -
- - - - - -
- ) : null} - {currentWindow == "social" ? ( -

Ill get around to this at some point

- ) : null} - {currentWindow == "account" ? ( -
- use pfp -
-
- + {currentWindow == "stats" ? ( +
+ + + + + +
+ ) : null} + {currentWindow == "social" ? ( +

Ill get around to this at some point

+ ) : null} + {currentWindow == "account" ? ( +
+ use pfp -
+
+
- -
-
- -
- ) : null} + + ) : null} + + ) : ( +

+ Authenticating User +

+ )} ); } diff --git a/app/history/page.tsx b/app/history/page.tsx index c73c378..3af655b 100644 --- a/app/history/page.tsx +++ b/app/history/page.tsx @@ -3,6 +3,7 @@ import getAllSessions from "@/utils/score/getAllSessions"; import FinalScoringStats from "@/components/scoring/finalScoringStats"; import ScoringChart from "@/components/scoring/scoringChart"; +import { useAuthContext } from "@context/authContext"; import Dropdown from "@/components/general/dropdown"; import { doc, getDoc } from "firebase/firestore"; import Button from "@/components/general/button"; @@ -14,6 +15,7 @@ export default function History() { const [currentGameName, setCurrentGameName] = useState(""); const [gameNameList, setGameNameList] = useState([] as string[]); const [dateMap, setDateMap] = useState(new Map()); + const { user } = useAuthContext() as { user: any }; // session info const [arrowsPerEnd, setArrowsPerEnd] = useState(0); @@ -27,17 +29,22 @@ export default function History() { const [bow, setBow] = useState(""); useEffect(() => { - getAllSessions(auth.currentUser).then(({ sortedMap, dateMap }) => { - setDateMap(dateMap); - setCurrentGame(dateMap.size); - setCurrentGameName(sortedMap.keys().next().value); + if (!user) return; + setupHistory(); + }, [user]); - let listOfGames = Array.from(sortedMap.keys()); - setGameNameList(listOfGames); + const setupHistory = async () => { + let { sortedMap, dateMap } = await getAllSessions(auth.currentUser); - getScoreDoc(sortedMap.values().next().value); - }); - }, []); + setDateMap(dateMap); + setCurrentGame(dateMap.size); + setCurrentGameName(sortedMap.keys().next().value); + + let listOfGames = Array.from(sortedMap.keys()); + setGameNameList(listOfGames); + + getScoreDoc(sortedMap.values().next().value); + }; const getScoreDoc = async (id: string) => { if (!auth.currentUser) return; @@ -57,7 +64,11 @@ export default function History() { } }; + //!!! dropdown name not updating const changeGame = (date: string) => { + setCurrentGameName(date); + let reverseGameNameList = gameNameList.slice().reverse(); + setCurrentGame(reverseGameNameList.indexOf(date) + 1); getScoreDoc(dateMap.get(date)); }; @@ -84,38 +95,46 @@ export default function History() { return (
-
- {}} - /> -
-
-
-
-

- {`${location} ${distance}${distanceUnit} ${bow}`} -

-
- {score.length > 0 ? ( -
- - -
- ) : null} + {user ? ( + <> +
+ +
+
+
+
+

+ {`${location} ${distance}${distanceUnit} ${bow}`} +

+
+ {score.length > 0 ? ( +
+ + +
+ ) : null} + + ) : ( +

+ Authenticating User +

+ )}
); }