diff --git a/app/(auth)/_layout.tsx b/app/(auth)/_layout.tsx index 89585e4..feaef0a 100644 --- a/app/(auth)/_layout.tsx +++ b/app/(auth)/_layout.tsx @@ -255,7 +255,7 @@ export default function TabLayout() { />*/} { props.navigation.navigate("todos"); @@ -400,8 +400,8 @@ export default function TabLayout() { drawerLabel: "To-Do", title: Device.deviceType === DeviceType.TABLET - ? "Family To Do's" - : "To Do's", + ? "Family To Dos" + : "To Dos", }} /> Move to - my to do's + my to dos diff --git a/components/pages/todos/ToDosPage.tsx b/components/pages/todos/ToDosPage.tsx index 53269c0..fc42bb2 100644 --- a/components/pages/todos/ToDosPage.tsx +++ b/components/pages/todos/ToDosPage.tsx @@ -41,7 +41,7 @@ const ToDosPage = () => { - Return to To Do's + Return to To Dos @@ -123,7 +123,7 @@ const FamilyChoresProgress = ({ - x/y chores completed + {`${child?.weeklyCompletedTodos ?? 0}/y chores completed`} diff --git a/hooks/firebase/types/profileTypes.ts b/hooks/firebase/types/profileTypes.ts index 5af414f..4d5e478 100644 --- a/hooks/firebase/types/profileTypes.ts +++ b/hooks/firebase/types/profileTypes.ts @@ -44,5 +44,7 @@ export interface UserProfile { microsoftAccounts?: { [email: string]: MicrosoftAccount }; appleAccounts?: { [email: string]: AppleAccount }; weeklyPoints?: number; + weeklyDayPoints?: Object; allTimePoints?: number; + weeklyCompletedTodos?: number; } \ No newline at end of file diff --git a/hooks/firebase/useUpdateTodo.ts b/hooks/firebase/useUpdateTodo.ts index 01356bf..71ecff0 100644 --- a/hooks/firebase/useUpdateTodo.ts +++ b/hooks/firebase/useUpdateTodo.ts @@ -130,16 +130,37 @@ export const useUpdateTodo = () => { ? userWeeklyPoints + todoUpdate.points : userWeeklyPoints - todoUpdate.points; + let pointsPerDay = userData.weeklyDayPoints || { + Monday: 0, + Tuesday: 0, + Wednesday: 0, + Thursday: 0, + Friday: 0, + Saturday: 0, + Sunday: 0, + }; + const currentDay = getCurrentDay(); + const updatedPointsPerDay = todoData.done + ? pointsPerDay[currentDay] + todoUpdate.points + : pointsPerDay[currentDay] - todoUpdate.points; + pointsPerDay[currentDay] = Math.max(0, updatedPointsPerDay); + let userAllTimePoints = userData.allTimePoints ?? 0; const allTimePoints = todoData.done ? userAllTimePoints + todoUpdate.points : userAllTimePoints - todoUpdate.points; + const weeklyCompletedTodos = todoData.done + ? (userData.weeklyCompletedTodos || 0) + 1 + : (userData.weeklyCompletedTodos || 0) - 1; + // Update the user's points in Firestore userData = { ...userData, weeklyPoints: weeklyPoints >= 0 ? weeklyPoints : 0, - allTimePoints: allTimePoints >= 0 ? allTimePoints : 0 + weeklyDayPoints: updatedPointsPerDay, + allTimePoints: allTimePoints >= 0 ? allTimePoints : 0, + weeklyCompletedTodos: weeklyCompletedTodos >= 0 ? weeklyCompletedTodos : 0 } userBatch.update(userRef, userData); }); @@ -161,4 +182,10 @@ export const useUpdateTodo = () => { queryClients.invalidateQueries({queryKey: ["todos"]}) } }) +}; + +const getCurrentDay = () => { + const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; + const now = new Date(); + return days[now.getDay()]; }; \ No newline at end of file