-
-
+ {currentWindow == "stats" ? (
+
+ ) : null}
+ {currentWindow == "social" ? (
+
Ill get around to this at some point
+ ) : null}
+ {currentWindow == "account" ? (
+
+
-
-
-
Social Profile
-
+
+
+
+
-
-
- googleSignOut()} />
- {}} />
-
-
-
- ) : 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 (
-
- {}}
- />
-
- switchGame("back")} />
- {`Game ${currentGame}/${gameNameList.length}`}
- switchGame("next")} />
-
-
-
-
- {`${location} ${distance}${distanceUnit} ${bow}`}
-
- {}} />
- {}} />
-
- {score.length > 0 ? (
-
- ) : null}
+ {user ? (
+ <>
+
+
+
+ switchGame("back")} />
+ {`Game ${currentGame}/${gameNameList.length}`}
+ switchGame("next")} />
+
+
+
+
+ {`${location} ${distance}${distanceUnit} ${bow}`}
+
+ {}} />
+ {}} />
+
+ {score.length > 0 ? (
+
+ ) : null}
+ >
+ ) : (
+
+ Authenticating User
+
+ )}
);
}