From 3ba7e89a3f343ff159c580412c1cdcb9df463afc Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 5 Apr 2024 18:43:35 -0700 Subject: [PATCH 01/10] plan hooked fully to database and finished by submitting drill --- add_user_data.py | 37 ++++ app/content/drill/[id]/description.js | 4 + app/content/drill/[id]/index.js | 3 + app/content/plan/index.js | 180 +++++++++++++++++++- app/segments/drill/[id]/submission/index.js | 2 +- app/segments/drill/[id]/submission/input.js | 59 ++++++- 6 files changed, 276 insertions(+), 9 deletions(-) create mode 100644 add_user_data.py diff --git a/add_user_data.py b/add_user_data.py new file mode 100644 index 00000000..a5e24bcc --- /dev/null +++ b/add_user_data.py @@ -0,0 +1,37 @@ +import random +import time +import math +import firebase_admin +from firebase_admin import firestore + +app = firebase_admin.initialize_app() +db = firestore.client() + +# Define the assigned_data array +assigned_data = [ + {"drill": "YtCsaxzscFScnpZYmnKI", "assigned_time": "1710522958", "completed": False}, + {"drill": "YtCsaxzscFScnpZYmnKI", "assigned_time": "1710464940", "completed": False}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710464941", "completed": False}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710292142", "completed": True}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710292143", "completed": False}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710292144", "completed": False}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710205745", "completed": True}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710205746", "completed": False}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710032940", "completed": False}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710032941", "completed": False}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710012940", "completed": False}, +] + +# Get a reference to the user collection +users_collection = db.collection("teams").document("1").collection("users") + + +print(users_collection.stream()) + + +# Loop through each document in the collection and update the assigned_data field +for doc in users_collection.stream(): + print(doc) + doc_ref = users_collection.document(doc.id) + doc_ref.update({'assigned_data': assigned_data}) + print(f"Document {doc.id} updated successfully.") \ No newline at end of file diff --git a/app/content/drill/[id]/description.js b/app/content/drill/[id]/description.js index 99d7c945..aa1e7f19 100644 --- a/app/content/drill/[id]/description.js +++ b/app/content/drill/[id]/description.js @@ -17,6 +17,9 @@ import { useDrillInfo } from "~/hooks/useDrillInfo"; export default function Description() { const drillId = useLocalSearchParams()["id"]; + const assignedDrill = useLocalSearchParams()["assigned"]; + + console.log("WAS IT ASSIGNED2", assignedDrill) const [activeIndex, setActiveIndex] = useState(0); const [modalVisible, setModalVisible] = useState(false); @@ -144,6 +147,7 @@ export default function Description() { diff --git a/app/content/drill/[id]/index.js b/app/content/drill/[id]/index.js index d45f0c64..dd379a80 100644 --- a/app/content/drill/[id]/index.js +++ b/app/content/drill/[id]/index.js @@ -16,6 +16,9 @@ export default function Index() { const navigation = useNavigation(); const drillId = useLocalSearchParams()["id"]; + const assignedDrill = useLocalSearchParams()["assigned"]; + + console.log("WAS IT ASSIGNED", assignedDrill) const { data: drillInfo, error: drillInfoError, diff --git a/app/content/plan/index.js b/app/content/plan/index.js index 5210973d..330ac46d 100644 --- a/app/content/plan/index.js +++ b/app/content/plan/index.js @@ -1,14 +1,186 @@ -import { PaperProvider, Text } from "react-native-paper"; +import React, { useState } from 'react'; import { SafeAreaView } from "react-native-safe-area-context"; +import { PaperProvider, Text, Avatar, Button, Card, Appbar } from "react-native-paper"; +import { TouchableOpacity } from 'react-native'; +import { FlatList, StyleSheet, ScrollView } from 'react-native'; +import Icon from "react-native-vector-icons/MaterialCommunityIcons"; +import { View } from 'react-native'; +import { useNavigation, router } from 'expo-router'; +import { Link } from 'expo-router'; +import drillsData from "~/drill_data.json"; +import { collection, doc, getDoc, getDocs, query, updateDoc, where } from "firebase/firestore"; +import { db } from "~/firebaseConfig"; +import { useEffect } from 'react'; + +import { formatDate, getUnique } from '~/Utility' +import { useDrillInfo } from "~/hooks/useDrillInfo"; +import { useUserInfo } from "~/hooks/useUserInfo"; +import Loading from "~/components/loading"; +import { currentAuthContext } from "~/context/Auth"; + + +const DrillList = () => { + const { currentUserId } = currentAuthContext(); + const userId = currentUserId ?? null; + + console.log("USER ID IN PLAN", userId) + + const { + data: drillInfo, + error: drillInfoError, + isLoading: drillInfoIsLoading, + } = useDrillInfo(); + + const { + data: userData, + userError: userError, + userIsLoading: userIsLoading, + } = useUserInfo(userId); + + const [assigned_data, setAssignedData] = useState([]); + + + console.log("USER DATA", userData); + + // Set the assigned_data state when the user data is loaded + useEffect(() => { + if (!userIsLoading && userData && userData.assigned_data) { + setAssignedData(userData.assigned_data); + } + }, [userIsLoading, userData]); + + // Group the assigned drills by date + const groupedData = assigned_data.reduce((acc, curr) => { + const date = convertTimestampToDate(curr.assigned_time); + if (!acc[date]) { + acc[date] = []; + } + acc[date].push(curr); + return acc; + }, {}); + + // Sort the dates in descending order + const sortedDates = Object.keys(groupedData).sort((a, b) => new Date(b) - new Date(a)); + const today = convertTimestampToDate(Date.now() / 1000); + + // Update the completed property of the clicked drill + + + // Render the list of drills + return userIsLoading || drillInfoIsLoading ? ( + + ) : ( + date} + renderItem={({ item: date }) => ( + + + {date === today ? 'Today' : date} + + {groupedData[date].map((drill) => ( + { + + router.push({ pathname: `content/drill/${drill.drill}`, params: { id: `${drill.drill}`, assigned: drill.assigned_time } }); + }} + > + + + {drillInfo[drill.drill]["drillType"]} + {drillInfo[drill.drill]["spec"]} + + + + ))} + + )} + /> + ); +}; + +const convertTimestampToDate = (timestamp) => { + const date = new Date(timestamp * 1000); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +}; + + + + + -//This is for the list of drills export default function Index() { + const d = doc(db, "teams", "1", "drills", "SpvYyY94HaulVH2zmVyM") + //getDoc(d).then(value => console.log(value.data())); + + const [cardDataTest, setCardDataTest] = React.useState([]) + useEffect(() => { + let drillList = []; + let promiseList = []; + /*Object.values(assigned_data).forEach((data) => { + data.drill = getDoc(doc(db, "teams", "1", "drills", data.drill)).then(drillData => ( + drillData.data() + )) + }); + console.log("DRILL LIST", drillList) + Object.values(assigned_data).forEach((data) => { + console.log("DATA", data) + drillList.push(data.drill); + });*/ + + /* assigned_data.drills.forEach(did => { + promiseList.push( + getDoc(doc(db, "teams", "1", "drills", did)).then(drillData => ( + drillData.data() + )) + ); + + }); + + Promise.all(promiseList).then(values => { + values.forEach((data) => { + console.log("DRILL DATA", data); + drillList.push(data); + }); + setCardDataTest(drillList); + });*/ + }, []); + console.log("TEST CARD DATA", cardDataTest) + console.log(formatDate(1710292140)) + + return ( - Plan Index + + + + + + + ); diff --git a/app/segments/drill/[id]/submission/index.js b/app/segments/drill/[id]/submission/index.js index 733b77a5..83b5fc63 100644 --- a/app/segments/drill/[id]/submission/index.js +++ b/app/segments/drill/[id]/submission/index.js @@ -9,7 +9,7 @@ import Result from "./result"; import { useDrillInfo } from "~/hooks/useDrillInfo"; export default function Index() { - const { id } = useLocalSearchParams(); + const { id, assigned } = useLocalSearchParams(); const [outputData, setOutputData] = useState([]); const [toggleResult, setToggleResult] = useState(false); diff --git a/app/segments/drill/[id]/submission/input.js b/app/segments/drill/[id]/submission/input.js index 1bae71c8..49b92f36 100644 --- a/app/segments/drill/[id]/submission/input.js +++ b/app/segments/drill/[id]/submission/input.js @@ -4,7 +4,7 @@ import { BottomSheetScrollView, } from "@gorhom/bottom-sheet"; import { useLocalSearchParams, useNavigation } from "expo-router"; -import { collection, doc, setDoc } from "firebase/firestore"; +import { collection, doc, setDoc, getDoc, updateDoc } from "firebase/firestore"; import { useEffect, useMemo, useRef, useState } from "react"; import { Pressable, StyleSheet, View } from "react-native"; import { GestureHandlerRootView } from "react-native-gesture-handler"; @@ -31,13 +31,58 @@ import Loading from "~/components/loading"; import { currentAuthContext } from "~/context/Auth"; import { db } from "~/firebaseConfig"; import Description from "./modals/description"; +import { useQueryClient } from '@tanstack/react-query'; /*************************************** * Firebase Upload ***************************************/ //A function to upload the outputData to the "attempts" collection -async function uploadAttempt(outputData) { + +async function completeAssigned(userId, teamId, assigned, queryClient) { + + console.log("WAS IT ASIGNED 5 and ID", assigned, userId) + + const userRef = doc(db, "teams", "1", "users", userId) + + const getDocument = async () => { + const docSnap = await getDoc(userRef); + + if (docSnap.exists()) { + console.log("Document data:", docSnap.data()); + + const assignedData = docSnap.data()["assigned_data"]; + const updatedAssignedData = assignedData.map((item, index) => { + if (item.assigned_time === assigned) { + return { ...item, completed: true }; + } + return item; + }); + + console.log("DOCUMENT DATA INSIDE", updatedAssignedData[0].completed); + + try { + await updateDoc(userRef, { assigned_data: updatedAssignedData }); + console.log("Document updated successfully!"); + queryClient.invalidateQueries(["user", { teamId, userId }]); + } catch (error) { + console.error("Error updating document:", error); + } + } else { + console.log("No such document!"); + } + }; + + getDocument(); + +} + + +async function uploadAttempt(outputData, userId, teamId, assigned, queryClient) { + + console.log("WAS IT ASIGNED 4 and ID", assigned, userId) + + try { //create new document const newAttemptRef = doc(collection(db, "teams", "1", "attempts")); @@ -51,7 +96,11 @@ async function uploadAttempt(outputData) { //upload the data await setDoc(newAttemptRef, uploadData).then(() => { console.log("Document successfully uploaded!"); - }); + completeAssigned(userId, teamId, assigned, queryClient); + }) + .catch((error) => { + console.error("Error uploading document: ", error); + }); } catch (e) { alert(e); console.log(e); @@ -284,6 +333,8 @@ function createOutputData( export default function Input({ drillInfo, setToggleResult, setOutputData }) { //Helper varibles + const { id, assigned } = useLocalSearchParams(); + const queryClient = useQueryClient(); const numInputs = drillInfo.inputs.length; @@ -350,7 +401,7 @@ export default function Input({ drillInfo, setToggleResult, setOutputData }) { ); setOutputData(outputData); - uploadAttempt(outputData); + uploadAttempt(outputData, auth["currentUserId"], auth["currentTeamId"], assigned, queryClient); setToggleResult(true); }} > From 55c0e6badf5f30619ce08f1b6fedfef59e2f9759 Mon Sep 17 00:00:00 2001 From: Andy Date: Sat, 6 Apr 2024 12:54:44 -0700 Subject: [PATCH 02/10] scroll down to refresh --- app/content/plan/index.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/content/plan/index.js b/app/content/plan/index.js index 330ac46d..083fce54 100644 --- a/app/content/plan/index.js +++ b/app/content/plan/index.js @@ -2,7 +2,7 @@ import React, { useState } from 'react'; import { SafeAreaView } from "react-native-safe-area-context"; import { PaperProvider, Text, Avatar, Button, Card, Appbar } from "react-native-paper"; import { TouchableOpacity } from 'react-native'; -import { FlatList, StyleSheet, ScrollView } from 'react-native'; +import { FlatList, StyleSheet, ScrollView, RefreshControl } from 'react-native'; import Icon from "react-native-vector-icons/MaterialCommunityIcons"; import { View } from 'react-native'; import { useNavigation, router } from 'expo-router'; @@ -18,10 +18,14 @@ import { useUserInfo } from "~/hooks/useUserInfo"; import Loading from "~/components/loading"; import { currentAuthContext } from "~/context/Auth"; +import { useQueryClient } from '@tanstack/react-query'; + const DrillList = () => { - const { currentUserId } = currentAuthContext(); + const queryClient = useQueryClient(); + const { currentUserId, currentTeamId } = currentAuthContext(); const userId = currentUserId ?? null; + const teamId = currentTeamId ?? null; console.log("USER ID IN PLAN", userId) @@ -39,6 +43,18 @@ const DrillList = () => { const [assigned_data, setAssignedData] = useState([]); + const [refreshing, setRefreshing] = React.useState(false); + + const onRefresh = React.useCallback(() => { + const refresh = async () => { + setRefreshing(true); + await queryClient.invalidateQueries(["user", { teamId, userId }]); + setRefreshing(false); + }; + + refresh(); + }, [teamId, userId, queryClient]); + console.log("USER DATA", userData); @@ -71,6 +87,9 @@ const DrillList = () => { ) : ( + } data={sortedDates} keyExtractor={(date) => date} renderItem={({ item: date }) => ( From ff5a105fb455e77ad08b6a08d6e3bc484d912742 Mon Sep 17 00:00:00 2001 From: Andy Date: Sat, 6 Apr 2024 13:13:27 -0700 Subject: [PATCH 03/10] change naming to be more clear and requre drill id and assigned_time --- app/content/drill/[id]/description.js | 6 +++--- app/content/drill/[id]/index.js | 4 ++-- app/content/plan/index.js | 2 +- app/segments/drill/[id]/submission/index.js | 2 +- app/segments/drill/[id]/submission/input.js | 21 +++++++++++++-------- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/content/drill/[id]/description.js b/app/content/drill/[id]/description.js index aa1e7f19..aa9f06f6 100644 --- a/app/content/drill/[id]/description.js +++ b/app/content/drill/[id]/description.js @@ -17,9 +17,9 @@ import { useDrillInfo } from "~/hooks/useDrillInfo"; export default function Description() { const drillId = useLocalSearchParams()["id"]; - const assignedDrill = useLocalSearchParams()["assigned"]; + const assigned_time = useLocalSearchParams()["assigned_time"]; - console.log("WAS IT ASSIGNED2", assignedDrill) + console.log("WAS IT ASSIGNED2", assigned_time) const [activeIndex, setActiveIndex] = useState(0); const [modalVisible, setModalVisible] = useState(false); @@ -147,7 +147,7 @@ export default function Description() { diff --git a/app/content/drill/[id]/index.js b/app/content/drill/[id]/index.js index dd379a80..e018e929 100644 --- a/app/content/drill/[id]/index.js +++ b/app/content/drill/[id]/index.js @@ -16,9 +16,9 @@ export default function Index() { const navigation = useNavigation(); const drillId = useLocalSearchParams()["id"]; - const assignedDrill = useLocalSearchParams()["assigned"]; + const assigned_time = useLocalSearchParams()["assigned_time"]; - console.log("WAS IT ASSIGNED", assignedDrill) + console.log("WAS IT ASSIGNED", assigned_time) const { data: drillInfo, error: drillInfoError, diff --git a/app/content/plan/index.js b/app/content/plan/index.js index 083fce54..bce03212 100644 --- a/app/content/plan/index.js +++ b/app/content/plan/index.js @@ -102,7 +102,7 @@ const DrillList = () => { disabled={drill.completed} onPress={() => { - router.push({ pathname: `content/drill/${drill.drill}`, params: { id: `${drill.drill}`, assigned: drill.assigned_time } }); + router.push({ pathname: `content/drill/${drill.drill}`, params: { id: `${drill.drill}`, assigned_time: drill.assigned_time } }); }} > diff --git a/app/segments/drill/[id]/submission/index.js b/app/segments/drill/[id]/submission/index.js index 83b5fc63..14c85a8c 100644 --- a/app/segments/drill/[id]/submission/index.js +++ b/app/segments/drill/[id]/submission/index.js @@ -9,7 +9,7 @@ import Result from "./result"; import { useDrillInfo } from "~/hooks/useDrillInfo"; export default function Index() { - const { id, assigned } = useLocalSearchParams(); + const { id, assigned_time } = useLocalSearchParams(); const [outputData, setOutputData] = useState([]); const [toggleResult, setToggleResult] = useState(false); diff --git a/app/segments/drill/[id]/submission/input.js b/app/segments/drill/[id]/submission/input.js index 1827606e..9c1044f1 100644 --- a/app/segments/drill/[id]/submission/input.js +++ b/app/segments/drill/[id]/submission/input.js @@ -39,9 +39,9 @@ import { useQueryClient } from '@tanstack/react-query'; //A function to upload the outputData to the "attempts" collection -async function completeAssigned(userId, teamId, assigned, queryClient) { +async function completeAssigned(userId, teamId, assigned_time, id, queryClient) { - console.log("WAS IT ASIGNED 5 and ID", assigned, userId) + console.log("WAS IT ASIGNED 5 and ID", assigned_time, userId) const userRef = doc(db, "teams", "1", "users", userId) @@ -53,7 +53,7 @@ async function completeAssigned(userId, teamId, assigned, queryClient) { const assignedData = docSnap.data()["assigned_data"]; const updatedAssignedData = assignedData.map((item, index) => { - if (item.assigned_time === assigned) { + if (item.assigned_time === assigned_time && item.drill === id) { return { ...item, completed: true }; } return item; @@ -78,9 +78,9 @@ async function completeAssigned(userId, teamId, assigned, queryClient) { } -async function uploadAttempt(outputData, userId, teamId, assigned, queryClient) { +async function uploadAttempt(outputData, userId, teamId, assigned_time, id, queryClient) { - console.log("WAS IT ASIGNED 4 and ID", assigned, userId) + console.log("WAS IT ASIGNED 4 and ID", assigned_time, userId) try { @@ -96,7 +96,9 @@ async function uploadAttempt(outputData, userId, teamId, assigned, queryClient) //upload the data await setDoc(newAttemptRef, uploadData).then(() => { console.log("Document successfully uploaded!"); - completeAssigned(userId, teamId, assigned, queryClient); + if (assigned_time) { + completeAssigned(userId, teamId, assigned_time, id, queryClient); + } }) .catch((error) => { console.error("Error uploading document: ", error); @@ -332,7 +334,10 @@ function createOutputData( export default function Input({ drillInfo, setToggleResult, setOutputData }) { //Helper varibles - const { id, assigned } = useLocalSearchParams(); + const { id, assigned_time } = useLocalSearchParams(); + + + console.log("ID AND THE ASSIGNED TIME", id, assigned_time) const queryClient = useQueryClient(); const numInputs = drillInfo.inputs.length; @@ -400,7 +405,7 @@ export default function Input({ drillInfo, setToggleResult, setOutputData }) { ); setOutputData(outputData); - uploadAttempt(outputData, auth["currentUserId"], auth["currentTeamId"], assigned, queryClient); + uploadAttempt(outputData, auth["currentUserId"], auth["currentTeamId"], assigned_time, id, queryClient); setToggleResult(true); }} > From bfd2d64212229ae72752fa8e9a4f5d5f82e18109 Mon Sep 17 00:00:00 2001 From: Andy Date: Sat, 6 Apr 2024 18:32:37 -0700 Subject: [PATCH 04/10] add assigned_data to user on user creation --- app/(auth)/signup.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/(auth)/signup.js b/app/(auth)/signup.js index 592dc152..70c14637 100644 --- a/app/(auth)/signup.js +++ b/app/(auth)/signup.js @@ -52,6 +52,7 @@ export default function SignUp() { // hardcoded "player" role for now, add role selection to profile settings in future PR role: "player", uid: userRef, + assigned_data: [], }); setCurrentUserId(userCredential.user.uid); From 38c183c7a5704393870ce87b2e7969ce38138025 Mon Sep 17 00:00:00 2001 From: Andy Date: Sun, 7 Apr 2024 16:53:03 -0700 Subject: [PATCH 05/10] fix key issue, lighter green, squircle, spacing of description --- add_user_data.py | 22 ++++---- app/content/plan/index.js | 102 +++++++++++++++++++------------------- 2 files changed, 62 insertions(+), 62 deletions(-) diff --git a/add_user_data.py b/add_user_data.py index a5e24bcc..e4fb25dc 100644 --- a/add_user_data.py +++ b/add_user_data.py @@ -9,17 +9,17 @@ # Define the assigned_data array assigned_data = [ - {"drill": "YtCsaxzscFScnpZYmnKI", "assigned_time": "1710522958", "completed": False}, - {"drill": "YtCsaxzscFScnpZYmnKI", "assigned_time": "1710464940", "completed": False}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710464941", "completed": False}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710292142", "completed": True}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710292143", "completed": False}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710292144", "completed": False}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710205745", "completed": True}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710205746", "completed": False}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710032940", "completed": False}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710032941", "completed": False}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1710012940", "completed": False}, + {"drill": "YtCsaxzscFScnpZYmnKI", "assigned_time": "1712531660", "completed": False}, + {"drill": "YtCsaxzscFScnpZYmnKI", "assigned_time": "1712531560", "completed": False}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1712531460", "completed": False}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1712531360", "completed": True}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1712531260", "completed": False}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1712470455", "completed": False}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1712470355", "completed": True}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1712470255", "completed": False}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1712384055", "completed": False}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1709709255", "completed": False}, + {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1709622855", "completed": False}, ] # Get a reference to the user collection diff --git a/app/content/plan/index.js b/app/content/plan/index.js index bce03212..b488b711 100644 --- a/app/content/plan/index.js +++ b/app/content/plan/index.js @@ -1,6 +1,6 @@ import React, { useState } from 'react'; import { SafeAreaView } from "react-native-safe-area-context"; -import { PaperProvider, Text, Avatar, Button, Card, Appbar } from "react-native-paper"; +import { PaperProvider, Text, Avatar, Button, Card, Appbar, List } from "react-native-paper"; import { TouchableOpacity } from 'react-native'; import { FlatList, StyleSheet, ScrollView, RefreshControl } from 'react-native'; import Icon from "react-native-vector-icons/MaterialCommunityIcons"; @@ -85,27 +85,36 @@ const DrillList = () => { // Render the list of drills return userIsLoading || drillInfoIsLoading ? ( + ) : sortedDates.length === 0 ? ( + + No drills assigned + ) : ( } data={sortedDates} - keyExtractor={(date) => date} + keyExtractor={(item, index) => item} renderItem={({ item: date }) => ( - - {date === today ? 'Today' : date} + + {date === today ? "Today" : date} {groupedData[date].map((drill) => ( { - - router.push({ pathname: `content/drill/${drill.drill}`, params: { id: `${drill.drill}`, assigned_time: drill.assigned_time } }); + router.push({ + pathname: `content/drill/${drill.drill}`, + params: { id: `${drill.drill}`, assigned_time: drill.assigned_time }, + }); }} > - + { alignItems: 'center', justifyContent: 'space-between', width: '100%', - height: 50, - backgroundColor: `${!drill.completed ? '#fff' : 'green'}`, - borderRadius: 50, + height: 80, // Increased height for better squircle shape + backgroundColor: `${!drill.completed ? '#fff' : '#89E894'}`, + borderRadius: 20, // Decreased borderRadius for more squircle shape marginBottom: 10, paddingLeft: 30, paddingRight: 30, - flexDirection: 'row', + paddingTop: 10, // Increased paddingTop for better squircle shape + paddingBottom: 10, // Increased paddingBottom for better squircle shape }} > {drillInfo[drill.drill]["drillType"]} - {drillInfo[drill.drill]["spec"]} + {drillInfo[drill.drill]["spec"]} @@ -144,49 +154,39 @@ const convertTimestampToDate = (timestamp) => { +const CoachView = () => { + const { + data: drillInfo, + error: drillInfoError, + isLoading: drillInfoIsLoading, + } = useDrillInfo(); + const [expanded, setExpanded] = React.useState(true); + const handlePress = () => setExpanded(!expanded); + if (drillInfoIsLoading) { + return ; + } + return ( + + }> + {drillInfo && Object.values(drillInfo).map((drill) => ())} -export default function Index() { - const d = doc(db, "teams", "1", "drills", "SpvYyY94HaulVH2zmVyM") - //getDoc(d).then(value => console.log(value.data())); + - const [cardDataTest, setCardDataTest] = React.useState([]) - useEffect(() => { - let drillList = []; - let promiseList = []; - /*Object.values(assigned_data).forEach((data) => { - data.drill = getDoc(doc(db, "teams", "1", "drills", data.drill)).then(drillData => ( - drillData.data() - )) - }); - console.log("DRILL LIST", drillList) - Object.values(assigned_data).forEach((data) => { - console.log("DATA", data) - drillList.push(data.drill); - });*/ - - /* assigned_data.drills.forEach(did => { - promiseList.push( - getDoc(doc(db, "teams", "1", "drills", did)).then(drillData => ( - drillData.data() - )) - ); - - }); - - Promise.all(promiseList).then(values => { - values.forEach((data) => { - console.log("DRILL DATA", data); - drillList.push(data); - }); - setCardDataTest(drillList); - });*/ - }, []); - console.log("TEST CARD DATA", cardDataTest) - console.log(formatDate(1710292140)) + + + ); +}; + + +export default function Index() { + const { data: userInfo, userIsLoading, userError } = useUserInfo(); + console.log("USER INFO IN PLAN BEGGINING", userInfo) return ( - + - + From 8db82d7480bd9ae2dd7f4d2063b40413764f014d Mon Sep 17 00:00:00 2001 From: Andy Date: Sun, 7 Apr 2024 16:55:36 -0700 Subject: [PATCH 06/10] styling --- app/content/plan/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/content/plan/index.js b/app/content/plan/index.js index b488b711..137b7455 100644 --- a/app/content/plan/index.js +++ b/app/content/plan/index.js @@ -122,14 +122,14 @@ const DrillList = () => { alignItems: 'center', justifyContent: 'space-between', width: '100%', - height: 80, // Increased height for better squircle shape + height: 65, backgroundColor: `${!drill.completed ? '#fff' : '#89E894'}`, - borderRadius: 20, // Decreased borderRadius for more squircle shape + borderRadius: 20, marginBottom: 10, paddingLeft: 30, paddingRight: 30, - paddingTop: 10, // Increased paddingTop for better squircle shape - paddingBottom: 10, // Increased paddingBottom for better squircle shape + paddingTop: 5, + paddingBottom: 5, }} > {drillInfo[drill.drill]["drillType"]} From 22f69aa05858f8224fff9461f280243f5c63ed3e Mon Sep 17 00:00:00 2001 From: Frankreed Date: Sun, 7 Apr 2024 16:59:40 -0700 Subject: [PATCH 07/10] updated prettier and github action settings to be more strict --- .github/workflows/main.yml | 2 +- package.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4c906f6c..12b5df3e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,4 +14,4 @@ jobs: - name: Install Prettier run: yarn add prettier --dev - name: Check code formatting - run: yarn pretty --check + run: yarn pretty:check diff --git a/package.json b/package.json index 27dda396..f5fcb531 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "ios": "expo start --ios", "web": "expo start --web", "pretty": "prettier --write .", + "pretty:check": "prettier --check .", "python": "./venv/bin/python", "firestore": "firebase emulators:start --only firestore" }, From 210a6af5be6c86c3e83fe6e83b27fcf31d81056a Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 8 Apr 2024 13:08:37 -0700 Subject: [PATCH 08/10] code cleanup --- add_user_data.py | 22 +-- app/content/drill/[id]/description.js | 6 +- app/content/drill/[id]/index.js | 6 +- app/content/plan/index.js | 146 ++++++++++---------- app/segments/drill/[id]/submission/index.js | 2 +- app/segments/drill/[id]/submission/input.js | 30 ++-- 6 files changed, 107 insertions(+), 105 deletions(-) diff --git a/add_user_data.py b/add_user_data.py index e4fb25dc..79308612 100644 --- a/add_user_data.py +++ b/add_user_data.py @@ -9,17 +9,17 @@ # Define the assigned_data array assigned_data = [ - {"drill": "YtCsaxzscFScnpZYmnKI", "assigned_time": "1712531660", "completed": False}, - {"drill": "YtCsaxzscFScnpZYmnKI", "assigned_time": "1712531560", "completed": False}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1712531460", "completed": False}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1712531360", "completed": True}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1712531260", "completed": False}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1712470455", "completed": False}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1712470355", "completed": True}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1712470255", "completed": False}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1712384055", "completed": False}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1709709255", "completed": False}, - {"drill": "SpvYyY94HaulVH2zmVyM", "assigned_time": "1709622855", "completed": False}, + {"drillId": "YtCsaxzscFScnpZYmnKI", "assignedTime": "1712600157", "completed": False}, + {"drillId": "YtCsaxzscFScnpZYmnKI", "assignedTime": "1712531560", "completed": False}, + {"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1712531460", "completed": False}, + {"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1712531360", "completed": True}, + {"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1712531260", "completed": False}, + {"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1712470455", "completed": False}, + {"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1712470355", "completed": True}, + {"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1712470255", "completed": False}, + {"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1712384055", "completed": False}, + {"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1709709255", "completed": False}, + {"drillId": "SpvYyY94HaulVH2zmVyM", "assignedTime": "1709622855", "completed": False}, ] # Get a reference to the user collection diff --git a/app/content/drill/[id]/description.js b/app/content/drill/[id]/description.js index aa9f06f6..f628ae59 100644 --- a/app/content/drill/[id]/description.js +++ b/app/content/drill/[id]/description.js @@ -17,9 +17,9 @@ import { useDrillInfo } from "~/hooks/useDrillInfo"; export default function Description() { const drillId = useLocalSearchParams()["id"]; - const assigned_time = useLocalSearchParams()["assigned_time"]; + const assignedTime = useLocalSearchParams()["assignedTime"]; - console.log("WAS IT ASSIGNED2", assigned_time) + console.log("WAS IT ASSIGNED2", assignedTime) const [activeIndex, setActiveIndex] = useState(0); const [modalVisible, setModalVisible] = useState(false); @@ -147,7 +147,7 @@ export default function Description() { diff --git a/app/content/drill/[id]/index.js b/app/content/drill/[id]/index.js index e018e929..25d5b6ee 100644 --- a/app/content/drill/[id]/index.js +++ b/app/content/drill/[id]/index.js @@ -14,11 +14,11 @@ import { useDrillInfo } from "~/hooks/useDrillInfo"; export default function Index() { const [value, setValue] = React.useState("description"); const navigation = useNavigation(); - const drillId = useLocalSearchParams()["id"]; + const { id: drillId, assignedTime: assignedTime } = useLocalSearchParams(); - const assigned_time = useLocalSearchParams()["assigned_time"]; - console.log("WAS IT ASSIGNED", assigned_time) + + console.log("WAS IT ASSIGNED", assignedTime) const { data: drillInfo, error: drillInfoError, diff --git a/app/content/plan/index.js b/app/content/plan/index.js index 137b7455..2db92e80 100644 --- a/app/content/plan/index.js +++ b/app/content/plan/index.js @@ -2,7 +2,7 @@ import React, { useState } from 'react'; import { SafeAreaView } from "react-native-safe-area-context"; import { PaperProvider, Text, Avatar, Button, Card, Appbar, List } from "react-native-paper"; import { TouchableOpacity } from 'react-native'; -import { FlatList, StyleSheet, ScrollView, RefreshControl } from 'react-native'; +import { FlatList, StyleSheet, ScrollView, RefreshControl, SectionList } from 'react-native'; import Icon from "react-native-vector-icons/MaterialCommunityIcons"; import { View } from 'react-native'; import { useNavigation, router } from 'expo-router'; @@ -22,12 +22,7 @@ import { useQueryClient } from '@tanstack/react-query'; const DrillList = () => { - const queryClient = useQueryClient(); const { currentUserId, currentTeamId } = currentAuthContext(); - const userId = currentUserId ?? null; - const teamId = currentTeamId ?? null; - - console.log("USER ID IN PLAN", userId) const { data: drillInfo, @@ -36,110 +31,117 @@ const DrillList = () => { } = useDrillInfo(); const { - data: userData, - userError: userError, + data: userInfo, + userError: userInfoError, userIsLoading: userIsLoading, - } = useUserInfo(userId); + } = useUserInfo(currentUserId); - const [assigned_data, setAssignedData] = useState([]); + const queryClient = useQueryClient(); + const [assignedData, setAssignedData] = useState([]); const [refreshing, setRefreshing] = React.useState(false); const onRefresh = React.useCallback(() => { const refresh = async () => { setRefreshing(true); - await queryClient.invalidateQueries(["user", { teamId, userId }]); + await queryClient.invalidateQueries(["user", { teamId: currentTeamId, userId: currentUserId }]); setRefreshing(false); }; - refresh(); - }, [teamId, userId, queryClient]); + }, [currentTeamId, currentUserId, queryClient]); - - console.log("USER DATA", userData); + console.log("USER DATA", userInfo); // Set the assigned_data state when the user data is loaded useEffect(() => { - if (!userIsLoading && userData && userData.assigned_data) { - setAssignedData(userData.assigned_data); + if (!userIsLoading && userInfo && userInfo.assigned_data) { + setAssignedData(userInfo.assigned_data); } - }, [userIsLoading, userData]); + }, [userIsLoading, userInfo]); + + if (userIsLoading || drillInfoIsLoading) { return } + + const today = convertTimestampToDate(Date.now() / 1000); // Group the assigned drills by date - const groupedData = assigned_data.reduce((acc, curr) => { - const date = convertTimestampToDate(curr.assigned_time); - if (!acc[date]) { - acc[date] = []; + const groupedData = assignedData.reduce((acc, curr) => { + const date = convertTimestampToDate(curr.assignedTime); + const dateKey = date === today ? "Today" : date; + + if (!acc[dateKey]) { + acc[dateKey] = []; + } + if (curr.completed) { + acc[dateKey].push(curr); + } + else { + acc[dateKey].unshift(curr); } - acc[date].push(curr); + return acc; }, {}); // Sort the dates in descending order const sortedDates = Object.keys(groupedData).sort((a, b) => new Date(b) - new Date(a)); - const today = convertTimestampToDate(Date.now() / 1000); - // Update the completed property of the clicked drill // Render the list of drills - return userIsLoading || drillInfoIsLoading ? ( - - ) : sortedDates.length === 0 ? ( + return sortedDates.length === 0 ? ( No drills assigned ) : ( - } - data={sortedDates} - keyExtractor={(item, index) => item} - renderItem={({ item: date }) => ( - - - {date === today ? "Today" : date} - - {groupedData[date].map((drill) => ( - { - router.push({ - pathname: `content/drill/${drill.drill}`, - params: { id: `${drill.drill}`, assigned_time: drill.assigned_time }, - }); + sections={sortedDates.map((date) => ({ + title: date, + data: groupedData[date], + }))} + keyExtractor={(item, index) => `${item.assignedTime}-${item.drillId}`} + renderItem={({ item: assignment }) => ( + { + router.push({ + pathname: `content/drill/${assignment.drillId}`, + params: { id: `${assignment.drillId}`, assignedTime: assignment.assignedTime }, + }); + }} + > + + - - - {drillInfo[drill.drill]["drillType"]} - {drillInfo[drill.drill]["spec"]} - - - - ))} - + {drillInfo[assignment.drillId]["prettyDrillType"]} + {drillInfo[assignment.drillId]["subType"]} + + + + )} + renderSectionHeader={({ section: { title } }) => ( + + {title} + )} + stickySectionHeadersEnabled={false} /> ); }; diff --git a/app/segments/drill/[id]/submission/index.js b/app/segments/drill/[id]/submission/index.js index 14c85a8c..ba9ad1c1 100644 --- a/app/segments/drill/[id]/submission/index.js +++ b/app/segments/drill/[id]/submission/index.js @@ -9,7 +9,7 @@ import Result from "./result"; import { useDrillInfo } from "~/hooks/useDrillInfo"; export default function Index() { - const { id, assigned_time } = useLocalSearchParams(); + const { id, assignedTime } = useLocalSearchParams(); const [outputData, setOutputData] = useState([]); const [toggleResult, setToggleResult] = useState(false); diff --git a/app/segments/drill/[id]/submission/input.js b/app/segments/drill/[id]/submission/input.js index 9c1044f1..63febd81 100644 --- a/app/segments/drill/[id]/submission/input.js +++ b/app/segments/drill/[id]/submission/input.js @@ -39,9 +39,9 @@ import { useQueryClient } from '@tanstack/react-query'; //A function to upload the outputData to the "attempts" collection -async function completeAssigned(userId, teamId, assigned_time, id, queryClient) { +async function completeAssigned(userId, teamId, assignedTime, drillId, attemptRefId, queryClient) { - console.log("WAS IT ASIGNED 5 and ID", assigned_time, userId) + console.log("WAS IT ASIGNED 5 and ID", assignedTime, userId) const userRef = doc(db, "teams", "1", "users", userId) @@ -52,11 +52,11 @@ async function completeAssigned(userId, teamId, assigned_time, id, queryClient) console.log("Document data:", docSnap.data()); const assignedData = docSnap.data()["assigned_data"]; - const updatedAssignedData = assignedData.map((item, index) => { - if (item.assigned_time === assigned_time && item.drill === id) { - return { ...item, completed: true }; + const updatedAssignedData = assignedData.map((assignment, index) => { + if (assignment.assignedTime === assignedTime && assignment.drillId === drillId) { + return { ...assignment, completed: true, attemptRefId: attemptRefId }; } - return item; + return assignment; }); console.log("DOCUMENT DATA INSIDE", updatedAssignedData[0].completed); @@ -78,9 +78,9 @@ async function completeAssigned(userId, teamId, assigned_time, id, queryClient) } -async function uploadAttempt(outputData, userId, teamId, assigned_time, id, queryClient) { +async function uploadAttempt(outputData, userId, teamId, assignedTime, drillId, queryClient) { - console.log("WAS IT ASIGNED 4 and ID", assigned_time, userId) + console.log("WAS IT ASIGNED 4 and ID", assignedTime, userId) try { @@ -96,8 +96,8 @@ async function uploadAttempt(outputData, userId, teamId, assigned_time, id, quer //upload the data await setDoc(newAttemptRef, uploadData).then(() => { console.log("Document successfully uploaded!"); - if (assigned_time) { - completeAssigned(userId, teamId, assigned_time, id, queryClient); + if (assignedTime) { + completeAssigned(userId, teamId, assignedTime, drillId, newAttemptRef.id, queryClient); } }) .catch((error) => { @@ -334,17 +334,17 @@ function createOutputData( export default function Input({ drillInfo, setToggleResult, setOutputData }) { //Helper varibles - const { id, assigned_time } = useLocalSearchParams(); + const { id, assignedTime } = useLocalSearchParams(); - console.log("ID AND THE ASSIGNED TIME", id, assigned_time) + console.log("ID AND THE ASSIGNED TIME", id, assignedTime) const queryClient = useQueryClient(); const numInputs = drillInfo.inputs.length; const navigation = useNavigation(); - const auth = currentAuthContext(); + const { currentUserId, currentTeamId } = currentAuthContext(); //a useState hook to track the inputs on each shot const [inputValues, setInputValues] = useState( @@ -398,14 +398,14 @@ export default function Input({ drillInfo, setToggleResult, setOutputData }) { let outputData = createOutputData( inputValues, attemptShots, - auth["currentUserId"], + currentUserId, did, drillInfo.outputs, drillInfo.aggOutputs, ); setOutputData(outputData); - uploadAttempt(outputData, auth["currentUserId"], auth["currentTeamId"], assigned_time, id, queryClient); + uploadAttempt(outputData, currentUserId, currentTeamId, assignedTime, id, queryClient); setToggleResult(true); }} > From c85eb5750b36f905a2c76901db9462cc0f2cc163 Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 8 Apr 2024 16:07:32 -0700 Subject: [PATCH 09/10] ran pretty --- app/content/drill/[id]/description.js | 2 +- app/content/drill/[id]/index.js | 4 +- app/content/plan/index.js | 119 +++++++++++--------- app/segments/drill/[id]/submission/input.js | 70 ++++++++---- 4 files changed, 113 insertions(+), 82 deletions(-) diff --git a/app/content/drill/[id]/description.js b/app/content/drill/[id]/description.js index f628ae59..ab461ea8 100644 --- a/app/content/drill/[id]/description.js +++ b/app/content/drill/[id]/description.js @@ -19,7 +19,7 @@ export default function Description() { const drillId = useLocalSearchParams()["id"]; const assignedTime = useLocalSearchParams()["assignedTime"]; - console.log("WAS IT ASSIGNED2", assignedTime) + console.log("WAS IT ASSIGNED2", assignedTime); const [activeIndex, setActiveIndex] = useState(0); const [modalVisible, setModalVisible] = useState(false); diff --git a/app/content/drill/[id]/index.js b/app/content/drill/[id]/index.js index 25d5b6ee..4d43cd93 100644 --- a/app/content/drill/[id]/index.js +++ b/app/content/drill/[id]/index.js @@ -16,9 +16,7 @@ export default function Index() { const navigation = useNavigation(); const { id: drillId, assignedTime: assignedTime } = useLocalSearchParams(); - - - console.log("WAS IT ASSIGNED", assignedTime) + console.log("WAS IT ASSIGNED", assignedTime); const { data: drillInfo, error: drillInfoError, diff --git a/app/content/plan/index.js b/app/content/plan/index.js index 2db92e80..2e3d12ad 100644 --- a/app/content/plan/index.js +++ b/app/content/plan/index.js @@ -1,25 +1,22 @@ -import React, { useState } from 'react'; +import { router } from "expo-router"; +import React, { useEffect, useState } from "react"; +import { + RefreshControl, + SectionList, + TouchableOpacity, + View, +} from "react-native"; +import { Appbar, List, PaperProvider, Text } from "react-native-paper"; import { SafeAreaView } from "react-native-safe-area-context"; -import { PaperProvider, Text, Avatar, Button, Card, Appbar, List } from "react-native-paper"; -import { TouchableOpacity } from 'react-native'; -import { FlatList, StyleSheet, ScrollView, RefreshControl, SectionList } from 'react-native'; -import Icon from "react-native-vector-icons/MaterialCommunityIcons"; -import { View } from 'react-native'; -import { useNavigation, router } from 'expo-router'; -import { Link } from 'expo-router'; -import drillsData from "~/drill_data.json"; -import { collection, doc, getDoc, getDocs, query, updateDoc, where } from "firebase/firestore"; -import { db } from "~/firebaseConfig"; -import { useEffect } from 'react'; - -import { formatDate, getUnique } from '~/Utility' -import { useDrillInfo } from "~/hooks/useDrillInfo"; -import { useUserInfo } from "~/hooks/useUserInfo"; + import Loading from "~/components/loading"; import { currentAuthContext } from "~/context/Auth"; +import { useDrillInfo } from "~/hooks/useDrillInfo"; +import { useUserInfo } from "~/hooks/useUserInfo"; -import { useQueryClient } from '@tanstack/react-query'; +import { useQueryClient } from "@tanstack/react-query"; +import { formatDate } from "../../../Utility"; const DrillList = () => { const { currentUserId, currentTeamId } = currentAuthContext(); @@ -44,7 +41,10 @@ const DrillList = () => { const onRefresh = React.useCallback(() => { const refresh = async () => { setRefreshing(true); - await queryClient.invalidateQueries(["user", { teamId: currentTeamId, userId: currentUserId }]); + await queryClient.invalidateQueries([ + "user", + { teamId: currentTeamId, userId: currentUserId }, + ]); setRefreshing(false); }; refresh(); @@ -59,13 +59,14 @@ const DrillList = () => { } }, [userIsLoading, userInfo]); - if (userIsLoading || drillInfoIsLoading) { return } - + if (userIsLoading || drillInfoIsLoading) { + return ; + } - const today = convertTimestampToDate(Date.now() / 1000); + const today = formatDate(Date.now() / 1000); // Group the assigned drills by date const groupedData = assignedData.reduce((acc, curr) => { - const date = convertTimestampToDate(curr.assignedTime); + const date = formatDate(curr.assignedTime); const dateKey = date === today ? "Today" : date; if (!acc[dateKey]) { @@ -73,8 +74,7 @@ const DrillList = () => { } if (curr.completed) { acc[dateKey].push(curr); - } - else { + } else { acc[dateKey].unshift(curr); } @@ -82,9 +82,9 @@ const DrillList = () => { }, {}); // Sort the dates in descending order - const sortedDates = Object.keys(groupedData).sort((a, b) => new Date(b) - new Date(a)); - - + const sortedDates = Object.keys(groupedData).sort( + (a, b) => new Date(b) - new Date(a), + ); // Render the list of drills return sortedDates.length === 0 ? ( @@ -108,7 +108,10 @@ const DrillList = () => { onPress={() => { router.push({ pathname: `content/drill/${assignment.drillId}`, - params: { id: `${assignment.drillId}`, assignedTime: assignment.assignedTime }, + params: { + id: `${assignment.drillId}`, + assignedTime: assignment.assignedTime, + }, }); }} > @@ -116,12 +119,12 @@ const DrillList = () => { { paddingBottom: 5, }} > - {drillInfo[assignment.drillId]["prettyDrillType"]} - {drillInfo[assignment.drillId]["subType"]} + + {drillInfo[assignment.drillId]["prettyDrillType"]} + + + {drillInfo[assignment.drillId]["subType"]} + )} renderSectionHeader={({ section: { title } }) => ( - + {title} )} @@ -146,16 +160,15 @@ const DrillList = () => { ); }; +/* const convertTimestampToDate = (timestamp) => { const date = new Date(timestamp * 1000); const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, '0'); - const day = String(date.getDate()).padStart(2, '0'); + const month = String(date.getMonth() + 1).padStart(2, "0"); + const day = String(date.getDate()).padStart(2, "0"); return `${year}-${month}-${day}`; }; - - - +*/ const CoachView = () => { const { data: drillInfo, @@ -170,38 +183,32 @@ const CoachView = () => { return ; } return ( - + }> - {drillInfo && Object.values(drillInfo).map((drill) => ())} - + left={(props) => } + > + {drillInfo && + Object.values(drillInfo).map((drill) => ( + + ))} - - ); }; - export default function Index() { const { data: userInfo, userIsLoading, userError } = useUserInfo(); - - console.log("USER INFO IN PLAN BEGGINING", userInfo) + console.log("USER INFO IN PLAN BEGGINING", userInfo); return ( - + - - ); diff --git a/app/segments/drill/[id]/submission/input.js b/app/segments/drill/[id]/submission/input.js index 63febd81..f6ab7cfb 100644 --- a/app/segments/drill/[id]/submission/input.js +++ b/app/segments/drill/[id]/submission/input.js @@ -3,8 +3,9 @@ import { BottomSheetModalProvider, BottomSheetScrollView, } from "@gorhom/bottom-sheet"; +import { useQueryClient } from "@tanstack/react-query"; import { useLocalSearchParams, useNavigation } from "expo-router"; -import { collection, doc, setDoc, getDoc, updateDoc } from "firebase/firestore"; +import { collection, doc, getDoc, setDoc, updateDoc } from "firebase/firestore"; import { useEffect, useMemo, useRef, useState } from "react"; import { Pressable, StyleSheet, View } from "react-native"; import { GestureHandlerRootView } from "react-native-gesture-handler"; @@ -31,7 +32,6 @@ import Loading from "~/components/loading"; import { currentAuthContext } from "~/context/Auth"; import { db } from "~/firebaseConfig"; import Description from "./modals/description"; -import { useQueryClient } from '@tanstack/react-query'; /*************************************** * Firebase Upload @@ -39,11 +39,17 @@ import { useQueryClient } from '@tanstack/react-query'; //A function to upload the outputData to the "attempts" collection -async function completeAssigned(userId, teamId, assignedTime, drillId, attemptRefId, queryClient) { - - console.log("WAS IT ASIGNED 5 and ID", assignedTime, userId) +async function completeAssigned( + userId, + teamId, + assignedTime, + drillId, + attemptRefId, + queryClient, +) { + console.log("WAS IT ASIGNED 5 and ID", assignedTime, userId); - const userRef = doc(db, "teams", "1", "users", userId) + const userRef = doc(db, "teams", "1", "users", userId); const getDocument = async () => { const docSnap = await getDoc(userRef); @@ -53,7 +59,10 @@ async function completeAssigned(userId, teamId, assignedTime, drillId, attemptRe const assignedData = docSnap.data()["assigned_data"]; const updatedAssignedData = assignedData.map((assignment, index) => { - if (assignment.assignedTime === assignedTime && assignment.drillId === drillId) { + if ( + assignment.assignedTime === assignedTime && + assignment.drillId === drillId + ) { return { ...assignment, completed: true, attemptRefId: attemptRefId }; } return assignment; @@ -74,14 +83,17 @@ async function completeAssigned(userId, teamId, assignedTime, drillId, attemptRe }; getDocument(); - } - -async function uploadAttempt(outputData, userId, teamId, assignedTime, drillId, queryClient) { - - console.log("WAS IT ASIGNED 4 and ID", assignedTime, userId) - +async function uploadAttempt( + outputData, + userId, + teamId, + assignedTime, + drillId, + queryClient, +) { + console.log("WAS IT ASIGNED 4 and ID", assignedTime, userId); try { //create new document @@ -94,12 +106,20 @@ async function uploadAttempt(outputData, userId, teamId, assignedTime, drillId, const uploadData = { ...outputData, id: newAttemptRef.id }; //upload the data - await setDoc(newAttemptRef, uploadData).then(() => { - console.log("Document successfully uploaded!"); - if (assignedTime) { - completeAssigned(userId, teamId, assignedTime, drillId, newAttemptRef.id, queryClient); - } - }) + await setDoc(newAttemptRef, uploadData) + .then(() => { + console.log("Document successfully uploaded!"); + if (assignedTime) { + completeAssigned( + userId, + teamId, + assignedTime, + drillId, + newAttemptRef.id, + queryClient, + ); + } + }) .catch((error) => { console.error("Error uploading document: ", error); }); @@ -336,8 +356,7 @@ export default function Input({ drillInfo, setToggleResult, setOutputData }) { //Helper varibles const { id, assignedTime } = useLocalSearchParams(); - - console.log("ID AND THE ASSIGNED TIME", id, assignedTime) + console.log("ID AND THE ASSIGNED TIME", id, assignedTime); const queryClient = useQueryClient(); const numInputs = drillInfo.inputs.length; @@ -405,7 +424,14 @@ export default function Input({ drillInfo, setToggleResult, setOutputData }) { ); setOutputData(outputData); - uploadAttempt(outputData, currentUserId, currentTeamId, assignedTime, id, queryClient); + uploadAttempt( + outputData, + currentUserId, + currentTeamId, + assignedTime, + id, + queryClient, + ); setToggleResult(true); }} > From a43ab70811be3972178fa35885910e86547a454c Mon Sep 17 00:00:00 2001 From: Frankreed Date: Mon, 8 Apr 2024 22:13:23 -0700 Subject: [PATCH 10/10] attemptRefId into attemptId --- app/segments/drill/[id]/submission/input.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/segments/drill/[id]/submission/input.js b/app/segments/drill/[id]/submission/input.js index f6ab7cfb..975032cd 100644 --- a/app/segments/drill/[id]/submission/input.js +++ b/app/segments/drill/[id]/submission/input.js @@ -44,7 +44,7 @@ async function completeAssigned( teamId, assignedTime, drillId, - attemptRefId, + attemptId, queryClient, ) { console.log("WAS IT ASIGNED 5 and ID", assignedTime, userId); @@ -63,7 +63,7 @@ async function completeAssigned( assignment.assignedTime === assignedTime && assignment.drillId === drillId ) { - return { ...assignment, completed: true, attemptRefId: attemptRefId }; + return { ...assignment, completed: true, attemptId: attemptId }; } return assignment; });