-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed all uses of direct firebase querying to tanstack query hooks.
- Loading branch information
1 parent
7b02668
commit d24dea6
Showing
21 changed files
with
416 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,37 @@ | ||
import { useLocalSearchParams } from "expo-router"; | ||
import { useContext, useEffect, useState } from "react"; | ||
|
||
import { | ||
collection, | ||
doc, | ||
getDoc, | ||
getDocs, | ||
query, | ||
where, | ||
} from "firebase/firestore"; | ||
import { useContext } from "react"; | ||
import BarChartScreen from "~/components/barChart"; | ||
import ErrorComponent from "~/components/errorComponent"; | ||
import Loading from "~/components/loading"; | ||
import { CurrentUserContext } from "~/contexts/CurrentUserContext"; | ||
import db from "~/firebaseConfig"; | ||
import { useAttempts } from "~/hooks/useAttempts"; | ||
import { useDrillInfo } from "~/hooks/useDrillInfo"; | ||
|
||
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) => { | ||
// get drill data | ||
if (doc.exists()) { | ||
setDrillInfo(doc.data()); | ||
} else { | ||
// doc.data() will be undefined in this case | ||
console.log("No such document!"); | ||
} | ||
}); | ||
getDocs( | ||
query( | ||
collection(db, "teams", "1", "attempts"), | ||
where("did", "==", drillId), | ||
where("uid", "==", userId), | ||
), | ||
) | ||
.then((querySnapshot) => { | ||
// get all attempts in drill and filter only the highest score for a user | ||
let newDrillAttempts = []; | ||
querySnapshot.forEach((doc) => newDrillAttempts.push(doc.data())); | ||
setDrillAttempts(newDrillAttempts); | ||
}) | ||
.catch((error) => { | ||
console.log("Error getting documents: ", error); | ||
}); | ||
return () => {}; | ||
}, []); | ||
|
||
const { | ||
data: drillInfo, | ||
isLoading: drillInfoIsLoading, | ||
drillInfoError, | ||
} = useDrillInfo(drillId); | ||
|
||
const { | ||
data: drillAttempts, | ||
isLoading: drillAttemptsIsLoading, | ||
error: drillAttemptsError, | ||
} = useAttempts({ drillId, userId }); | ||
|
||
if (drillInfoIsLoading || drillAttemptsIsLoading) { | ||
return <Loading />; | ||
} | ||
|
||
if (drillInfoError || drillAttemptsError) { | ||
return <ErrorComponent message={[drillInfoError, drillAttemptsError]} />; | ||
} | ||
// console.log(drillAttempts); | ||
|
||
return <BarChartScreen drillData={drillAttempts} drillInfo={drillInfo} />; | ||
} |
Oops, something went wrong.