diff --git a/Contexts.js b/Contexts.js new file mode 100644 index 00000000..6f1bdb92 --- /dev/null +++ b/Contexts.js @@ -0,0 +1,3 @@ +import { createContext } from "react"; + +export const CurrentUserContext = createContext("c0nEyjaOMhItMQTLMY0X"); diff --git a/app/_layout.js b/app/_layout.js index a47cf1a0..594f8b05 100644 --- a/app/_layout.js +++ b/app/_layout.js @@ -1,8 +1,16 @@ import { Stack } from "expo-router"; +import { useState } from "react"; +import { CurrentUserContext } from "~/Contexts"; export default function RootLayoutNav() { + const [currentUser, setCurrentUser] = useState("c0nEyjaOMhItMQTLMY0X"); + + // Function to update the context value + const updateCurrentUser = (newValue) => { + setCurrentUser(newValue); + }; return ( - <> + - + ); } diff --git a/app/content/drill/[id]/attempts/[attempt].js b/app/content/drill/[id]/attempts/[attempt].js index 6f00ba87..8a056f2c 100644 --- a/app/content/drill/[id]/attempts/[attempt].js +++ b/app/content/drill/[id]/attempts/[attempt].js @@ -12,7 +12,7 @@ import { SafeAreaView } from "react-native-safe-area-context"; import ScatterChart from "react-native-scatter-chart"; import { numTrunc } from "~/Utility"; import ShotAccordion from "~/components/shotAccordion"; -import { db } from "~/firebaseConfig"; +import db from "~/firebaseConfig"; function Result() { const drillId = useLocalSearchParams()["id"]; @@ -58,7 +58,7 @@ function Result() { return ( <> - + Drill Results @@ -123,6 +123,7 @@ export default Result; const styles = StyleSheet.create({ container: { padding: 20, + paddingBottom: 0, }, header: { flexDirection: "row", diff --git a/app/content/drill/[id]/description.js b/app/content/drill/[id]/description.js index 37ef3e48..88379466 100644 --- a/app/content/drill/[id]/description.js +++ b/app/content/drill/[id]/description.js @@ -1,11 +1,16 @@ import { Link, useLocalSearchParams } from "expo-router"; -import { Image, View } from "react-native"; +import { Image, ScrollView } from "react-native"; import { Button, Text } from "react-native-paper"; export default function Description({ descData }) { const drillId = useLocalSearchParams()["id"]; return ( - + Description @@ -29,6 +34,6 @@ export default function Description({ descData }) { Start Drill - + ); } diff --git a/app/content/drill/[id]/index.js b/app/content/drill/[id]/index.js index a30ac86b..1fe1b8f3 100644 --- a/app/content/drill/[id]/index.js +++ b/app/content/drill/[id]/index.js @@ -8,7 +8,7 @@ import Stat from "./statistics"; import { doc, getDoc } from "firebase/firestore"; import { SafeAreaView } from "react-native-safe-area-context"; -import { db } from "~/firebaseConfig"; +import db from "~/firebaseConfig"; export default function Index() { const [value, setValue] = React.useState("description"); @@ -38,7 +38,7 @@ export default function Index() { return ( - + { diff --git a/app/content/drill/[id]/leaderboard.js b/app/content/drill/[id]/leaderboard.js index 54583af3..4eaad76a 100644 --- a/app/content/drill/[id]/leaderboard.js +++ b/app/content/drill/[id]/leaderboard.js @@ -11,7 +11,7 @@ import { useEffect, useState } from "react"; import { ScrollView, View } from "react-native"; import { Avatar, Icon, List, Text } from "react-native-paper"; import { numTrunc } from "~/Utility"; -import { db } from "~/firebaseConfig"; +import db from "~/firebaseConfig"; export default function Leaderboard() { const drillId = useLocalSearchParams()["id"]; diff --git a/app/content/drill/[id]/statistics.js b/app/content/drill/[id]/statistics.js index b94c439d..9fc7ce1a 100644 --- a/app/content/drill/[id]/statistics.js +++ b/app/content/drill/[id]/statistics.js @@ -1,5 +1,5 @@ import { useLocalSearchParams } from "expo-router"; -import { useEffect, useState } from "react"; +import { useContext, useEffect, useState } from "react"; import { collection, @@ -9,13 +9,15 @@ import { query, where, } from "firebase/firestore"; +import { CurrentUserContext } from "~/Contexts"; import BarChartScreen from "~/components/barChart"; -import { db } from "~/firebaseConfig"; +import db from "~/firebaseConfig"; export default function Stat() { const drillId = useLocalSearchParams()["id"]; const [drillInfo, setDrillInfo] = useState(""); const [drillAttempts, setDrillAttempts] = useState([]); + const userId = useContext(CurrentUserContext)["currentUser"]; useEffect(() => { // massive data fetching on refresh. May or may not get its data from cache getDoc(doc(db, "teams", "1", "drills", drillId)).then((doc) => { @@ -31,7 +33,7 @@ export default function Stat() { query( collection(db, "teams", "1", "attempts"), where("did", "==", drillId), - where("uid", "==", "c0nEyjaOMhItMQTLMY0X"), + where("uid", "==", userId), ), ) .then((querySnapshot) => { @@ -45,9 +47,5 @@ export default function Stat() { }); return () => {}; }, []); - return ( - <> - - - ); + return ; } diff --git a/app/content/drill/index.js b/app/content/drill/index.js index 14a58d34..70e2bdd3 100644 --- a/app/content/drill/index.js +++ b/app/content/drill/index.js @@ -5,7 +5,7 @@ import { Appbar, List, PaperProvider } from "react-native-paper"; import { SafeAreaView } from "react-native-safe-area-context"; import { collection, getDocs } from "firebase/firestore"; -import { db } from "~/firebaseConfig"; +import db from "~/firebaseConfig"; export default function Index() { const [drills, setDrills] = React.useState([]); // [{} @@ -33,12 +33,6 @@ export default function Index() { - { - navigation.goBack(); - }} - color={"#F24E1E"} - /> diff --git a/app/content/profile/drills/[id].js b/app/content/profile/drills/[id].js index ce22d6e4..985b5d90 100644 --- a/app/content/profile/drills/[id].js +++ b/app/content/profile/drills/[id].js @@ -1,5 +1,5 @@ -import { useLocalSearchParams } from "expo-router"; -import { useEffect, useState } from "react"; +import { useLocalSearchParams, useNavigation } from "expo-router"; +import { useContext, useEffect, useState } from "react"; import { collection, @@ -11,13 +11,16 @@ import { } from "firebase/firestore"; import { Appbar, PaperProvider } from "react-native-paper"; import { SafeAreaView } from "react-native-safe-area-context"; +import { CurrentUserContext } from "~/Contexts"; import BarChartScreen from "~/components/barChart"; -import { db } from "~/firebaseConfig"; +import db from "~/firebaseConfig"; export default function Stat() { const drillId = useLocalSearchParams()["id"]; + const userId = useContext(CurrentUserContext)["currentUser"]; const [drillInfo, setDrillInfo] = useState(""); const [drillAttempts, setDrillAttempts] = useState([]); + const navigation = useNavigation(); useEffect(() => { // massive data fetching on refresh. May or may not get its data from cache getDoc(doc(db, "teams", "1", "drills", drillId)).then((doc) => { @@ -34,7 +37,7 @@ export default function Stat() { query( collection(db, "teams", "1", "attempts"), where("did", "==", drillId), - where("uid", "==", "c0nEyjaOMhItMQTLMY0X"), + where("uid", "==", userId), ), ) .then((querySnapshot) => { @@ -50,7 +53,7 @@ export default function Stat() { }, []); return ( - + { diff --git a/app/content/profile/index.js b/app/content/profile/index.js index acf3cf10..72241fd9 100644 --- a/app/content/profile/index.js +++ b/app/content/profile/index.js @@ -1,29 +1,56 @@ import { useNavigation } from "expo-router"; +import { + collection, + doc, + getDoc, + getDocs, + query, + where, +} from "firebase/firestore"; +import { useContext, useEffect, useState } from "react"; import { ScrollView, StyleSheet, Text, View } from "react-native"; import { Appbar, PaperProvider } from "react-native-paper"; import { SafeAreaView } from "react-native-safe-area-context"; +import { CurrentUserContext } from "~/Contexts"; import DrillCard from "~/components/drillCard"; import ProfileCard from "~/components/profileCard"; -import drillData from "~/drill_data.json"; +import db from "~/firebaseConfig"; function Index(props) { const navigation = useNavigation(); - const user = drillData["teams"]["1"]["users"]["1"]; - const drills = drillData["teams"]["1"]["drills"]; - const attemptedDrills = user["history"] - ? Object.keys(drills).filter((drillId) => drillId in user["history"]) - : []; + const [userData, setUserData] = useState({}); + const userId = useContext(CurrentUserContext)["currentUser"]; + const [drills, setDrills] = useState({}); + + useEffect(() => { + let uniqueDrills = new Set(); + getDoc(doc(db, "teams", "1", "users", userId)).then((doc) => { + setUserData(doc.data()); + }); + getDocs( + query(collection(db, "teams", "1", "attempts")), + where("uid", "==", userId), + ).then((querySnapshot) => { + querySnapshot.forEach((doc) => { + uniqueDrills.add(doc.data()["did"]); + }); + }); + getDocs( + query(collection(db, "teams", "1", "drills")), + where("did", "in", uniqueDrills), + ).then((querySnapshot) => { + let newDrills = {}; + querySnapshot.forEach((doc) => { + newDrills[doc.id] = doc.data(); + }); + setDrills(newDrills); + }); + }, []); return ( - + - { - navigation.goBack(); - }} - color={"#F24E1E"} - /> - + Drill History - {user["history"] ? ( - attemptedDrills.map((drillId) => { + {Object.keys(drills).length > 0 ? ( + Object.keys(drills).map((drillId) => { return ( - { - navigation.goBack(); - }} - color={"#F24E1E"} - /> diff --git a/app/content/team/users/[user]/drills/[id].js b/app/content/team/users/[user]/drills/[id].js index dcf176a5..220b7364 100644 --- a/app/content/team/users/[user]/drills/[id].js +++ b/app/content/team/users/[user]/drills/[id].js @@ -13,7 +13,7 @@ import { } from "firebase/firestore"; import { useEffect, useState } from "react"; import BarChartScreen from "~/components/barChart"; -import { db } from "~/firebaseConfig"; +import db from "~/firebaseConfig"; export default function Stat() { const navigation = useNavigation(); @@ -54,7 +54,7 @@ export default function Stat() { }, []); return ( - + { diff --git a/app/content/team/users/[user]/index.js b/app/content/team/users/[user]/index.js index 6125cd09..f89ccacd 100644 --- a/app/content/team/users/[user]/index.js +++ b/app/content/team/users/[user]/index.js @@ -13,7 +13,7 @@ import { Appbar, PaperProvider } from "react-native-paper"; import { SafeAreaView } from "react-native-safe-area-context"; import DrillCard from "~/components/drillCard"; import ProfileCard from "~/components/profileCard"; -import { db } from "~/firebaseConfig"; +import db from "~/firebaseConfig"; import { refToID } from "~/Utility"; function Index(props) { diff --git a/components/barChart.js b/components/barChart.js index 01d6c333..f0aff71c 100644 --- a/components/barChart.js +++ b/components/barChart.js @@ -131,13 +131,11 @@ export default function BarChartScreen({ drillData, drillInfo }) { }; const styles = StyleSheet.create({ - barChartComponent: { - marginTop: 13, - }, movingAvgContainer: { flexDirection: "row", alignItems: "center", marginBottom: 20, + marginTop: 13, zIndex: 3, justifyContent: "center", // Center the content horizontally }, @@ -201,7 +199,7 @@ export default function BarChartScreen({ drillData, drillInfo }) { }, bottomContainer: { marginTop: 20, - marginBottom: 20, + // marginBottom: 20, }, bottomTextContainer: { flexDirection: "row", @@ -214,107 +212,86 @@ export default function BarChartScreen({ drillData, drillInfo }) { fontSize: 13, color: "#333", // Adjust text color }, - scrollView: { - marginBottom: 70, - }, }); return ( - - - - Moving Avg. + + + Moving Avg. - - + + - - `${value}`} // Format label as needed - /> - - - - item.value} + + `${value}`} // Format label as needed + /> + + + + item.value} + pointerEvents={"none"} + > + + - - - - {/* item.value}*/} - {/*>*/} - - - - - - - {dateString} - - MA: {numTrunc(movingAvgData[selected])} - - - SG: {numTrunc(data[selected])} - + style={{ pointerEvents: "none" }} + /> + + + - {drillDataSorted[selected]["shots"].map((shot) => ( - - ))} + + + {dateString} + + MA: {numTrunc(movingAvgData[selected])} + + SG: {numTrunc(data[selected])} - - + + {drillDataSorted[selected]["shots"].map((shot) => ( + + ))} + + ); } diff --git a/firebaseConfig.js b/firebaseConfig.js index ca2d6dc0..55226fd4 100644 --- a/firebaseConfig.js +++ b/firebaseConfig.js @@ -22,4 +22,4 @@ const firebaseConfig = { const app = initializeApp(firebaseConfig); const db = getFirestore(app); -module.exports = { db }; +module.exports = db;