diff --git a/components/pages/(tablet_pages)/chores/SingleUserChoreList.tsx b/components/pages/(tablet_pages)/chores/SingleUserChoreList.tsx
index 38f246f..f05bfed 100644
--- a/components/pages/(tablet_pages)/chores/SingleUserChoreList.tsx
+++ b/components/pages/(tablet_pages)/chores/SingleUserChoreList.tsx
@@ -1,5 +1,5 @@
import { View, Text, TouchableOpacity, Icon } from "react-native-ui-lib";
-import React, { useState } from "react";
+import React, {useEffect, useState} from "react";
import { useToDosContext } from "@/contexts/ToDosContext";
import {
addDays,
@@ -20,7 +20,7 @@ const groupToDosByDate = (toDos: IToDo[]) => {
const dateB = b.date === null ? new Date() : b.date;
return dateA - dateB;
});
-
+
return sortedTodos.reduce(
(groups, toDo) => {
let dateKey;
@@ -44,7 +44,7 @@ const groupToDosByDate = (toDos: IToDo[]) => {
today.setHours(0, 0, 0, 0);
return date < today;
};
-
+
if (isOverdue(toDo.date) && !toDo.done) {
dateKey = "Overdue";
} else if (toDo.date === null || isToday(toDo.date)) {
@@ -95,8 +95,18 @@ const filterToDosByUser = (toDos: IToDo[], uid: string | undefined) => {
const SingleUserChoreList = ({ user }: { user: UserProfile }) => {
const { toDos } = useToDosContext();
- const userTodos = filterToDosByUser(toDos, user.uid);
- const groupedToDos = groupToDosByDate(userTodos);
+ const [localTodos, setLocalTodos] = useState([]);
+ const [groupedToDos, setGroupedToDos] = useState([]);
+
+ useEffect(() => {
+ const userTodos = filterToDosByUser(toDos, user.uid);
+ setLocalTodos(userTodos);
+ }, [toDos, user]);
+
+ useEffect(() => {
+ const grouped = groupToDosByDate(localTodos);
+ setGroupedToDos(grouped);
+ }, [localTodos]);
const [expandedGroups, setExpandedGroups] = useState<{
[key: string]: boolean;
@@ -186,7 +196,12 @@ const SingleUserChoreList = ({ user }: { user: UserProfile }) => {
{sortedItems.map((item) => (
-
+
))}
);
@@ -235,6 +250,8 @@ const SingleUserChoreList = ({ user }: { user: UserProfile }) => {
key={item.id}
item={item}
is7Days={dateKey === "Next 7 Days"}
+ localTodos={localTodos}
+ setLocalTodos={setLocalTodos}
/>
))}
@@ -278,7 +295,7 @@ const SingleUserChoreList = ({ user }: { user: UserProfile }) => {
{expandNoDate &&
noDateToDos
.sort((a, b) => Number(a.done) - Number(b.done))
- .map((item) => )}
+ .map((item) => )}
)}
diff --git a/components/pages/grocery/EditGroceryItem.tsx b/components/pages/grocery/EditGroceryItem.tsx
index 36b84e1..350fdd3 100644
--- a/components/pages/grocery/EditGroceryItem.tsx
+++ b/components/pages/grocery/EditGroceryItem.tsx
@@ -68,7 +68,7 @@ const EditGroceryItem = ({
);
const handleClose = () => {
- setGrocery(defaultGroceryItem);
+ closeEdit();
}
const handleSubmit = () => {
diff --git a/components/pages/grocery/GroceryItem.tsx b/components/pages/grocery/GroceryItem.tsx
index 4c20ab4..6763f2b 100644
--- a/components/pages/grocery/GroceryItem.tsx
+++ b/components/pages/grocery/GroceryItem.tsx
@@ -39,6 +39,7 @@ const GroceryItem = ({
return `${firstName.charAt(0).toUpperCase()}${lastName.charAt(0).toUpperCase()}`;
};
+ const isEditable = (isParent || isCaregiver) && item.approved && !item.bought;
return (
-
- setOpenFreqEdit(false)}
- />
-
- {isEditingTitle ? (
- setIsEditingTitle(true) : null}>
+
+ setOpenFreqEdit(false)}
/>
- ) : (
-
- {(isParent || isCaregiver) && !item.bought ? (
- setIsEditingTitle(true)}>
+ {isEditingTitle ? (
+
+ ) : (
+
+ {(isParent || isCaregiver) && !item.bought ? (
+
+ {item.title}
+
+ ) : (
{item.title}
-
- ) : (
-
- {item.title}
-
- )}
-
- )}
+ )}
+
+ )}
- {!item.approved ? (
-
- {(isParent || isCaregiver) && (
- <>
-
- handleItemApproved(item.id, { approved: true })
+ {!item.approved ? (
+
+ {(isParent || isCaregiver) && (
+ <>
+
+ handleItemApproved(item.id, { approved: true })
+ }
+ />
+ {
+ handleItemApproved(item.id, { approved: false });
+ deleteGrocery(item.id);
+ }}
+ />
+ >
+ )}
+
+ ) : (
+ !isEditingTitle &&
+ (isParent || isCaregiver) && (
+
+ {item.bought &&
+ deleteGrocery(item.id)}
+ />
}
- />
- {
- handleItemApproved(item.id, { approved: false });
- deleteGrocery(item.id);
- }}
- />
- >
- )}
-
- ) : (
- !isEditingTitle &&
- (isParent || isCaregiver) && (
-
- {item.bought &&
- deleteGrocery(item.id)}
- />
- }
- {
- const updatedApprovedGroceries = approvedGroceries.map((grocery) => grocery.id === item.id ? {...grocery, bought: !item.bought} : grocery);
- setApprovedGroceries(updatedApprovedGroceries);
- updateGroceryItem({ id: item.id, bought: !item.bought })
- }}
- />
-
- )
- )}
-
+ {
+ const updatedApprovedGroceries = approvedGroceries.map((grocery) => grocery.id === item.id ? {...grocery, bought: !item.bought} : grocery);
+ setApprovedGroceries(updatedApprovedGroceries);
+ updateGroceryItem({ id: item.id, bought: !item.bought })
+ }}
+ />
+
+ )
+ )}
+
+
{!item.approved && (
<>
diff --git a/components/pages/todos/ProgressCard.tsx b/components/pages/todos/ProgressCard.tsx
index d73d8c9..28c9efc 100644
--- a/components/pages/todos/ProgressCard.tsx
+++ b/components/pages/todos/ProgressCard.tsx
@@ -1,11 +1,21 @@
-import {Text, View} from "react-native-ui-lib";
+import { Text, View } from "react-native-ui-lib";
import React from "react";
-import {ProgressBar} from "react-native-ui-lib/src/components/progressBar";
-import {useToDosContext} from "@/contexts/ToDosContext";
+import { ProgressBar } from "react-native-ui-lib/src/components/progressBar";
import FireworksOrangeIcon from "@/assets/svgs/FireworksOrangeIcon";
+import { useAuthContext } from "@/contexts/AuthContext";
+
+export const transformNumber = (value: number, progressLimit: number) => {
+ return Math.floor((value / progressLimit) * 100);
+}
+
+const PROGRESS_LIMIT = 1000;
const ProgressCard = ({children}: { children?: React.ReactNode }) => {
- const {maxPoints} = useToDosContext();
+ const { profileData } = useAuthContext();
+
+ const weeklyPoints = profileData?.weeklyPoints ?? 0;
+ const transformedWeeklyPoints = transformNumber(weeklyPoints, PROGRESS_LIMIT);
+
return (
{
- You have earned XX points this week!{" "}
+ You have earned {weeklyPoints} points this week!{" "}
{
/>
0
- {maxPoints}
+ {PROGRESS_LIMIT}
{children}
diff --git a/components/pages/todos/ToDosPage.tsx b/components/pages/todos/ToDosPage.tsx
index 2ad5b54..f4b6745 100644
--- a/components/pages/todos/ToDosPage.tsx
+++ b/components/pages/todos/ToDosPage.tsx
@@ -27,6 +27,7 @@ const ToDosPage = () => {
);
+
return (
<>
;
@@ -52,7 +53,7 @@ const FamilyChart = ({ children }: {
return {
stacks: stacks,
- label: day,
+ label: chartDayMap[day],
}
});
setDataList(data);
diff --git a/components/pages/todos/family-chores/FamilyChoresProgress.tsx b/components/pages/todos/family-chores/FamilyChoresProgress.tsx
index 36c842b..ceadde2 100644
--- a/components/pages/todos/family-chores/FamilyChoresProgress.tsx
+++ b/components/pages/todos/family-chores/FamilyChoresProgress.tsx
@@ -7,8 +7,8 @@ import { Ionicons } from "@expo/vector-icons";
import { useGetFamilyMembers } from "@/hooks/firebase/useGetFamilyMembers";
import { ProfileType } from "@/contexts/AuthContext";
import { ScrollView } from "react-native-gesture-handler";
-import {useFocusEffect} from "@react-navigation/core";
-import {UserProfile} from "@/hooks/firebase/types/profileTypes";
+import { useFocusEffect } from "@react-navigation/core";
+import { UserProfile } from "@/hooks/firebase/types/profileTypes";
const FamilyChoresProgress = ({
setPageIndex,
@@ -47,7 +47,7 @@ const FamilyChoresProgress = ({
- Family Chores Progress Report
+ Family Todos Progress Report
@@ -92,7 +92,7 @@ const FamilyChoresProgress = ({
style={{ fontFamily: "Manrope_700Bold", fontSize: 15 }}
marginV-20
>
- Chore Tracker
+ Todos Tracker
{children?.map((child) => (
- {`${child?.weeklyCompletedTodos ?? 0}/y chores completed`}
+ {`${child?.weeklyCompletedTodos ?? 0} todos completed`}
diff --git a/components/pages/todos/user-chores/UserChart.tsx b/components/pages/todos/user-chores/UserChart.tsx
index eeed824..af180b4 100644
--- a/components/pages/todos/user-chores/UserChart.tsx
+++ b/components/pages/todos/user-chores/UserChart.tsx
@@ -1,57 +1,53 @@
-import React from "react";
+import React, {useEffect, useState} from "react";
import { BarChart } from "react-native-gifted-charts";
+import {UserProfile} from "@/hooks/firebase/types/profileTypes";
+import {chartDayMap, weekOrder} from "@/constants/common";
-const UserChart = () => {
- const barColor = "#05a8b6"
- const data = [
- {
- value: 290, // Direct value of the bar
- frontColor: barColor, // Color of the bar
- label: "M",
- },
- {
- value: 190,
- frontColor: barColor,
- label: "Tu",
- },
- {
- value: 210,
- frontColor: barColor,
- label: "W",
- },
- {
- value: 410,
- frontColor: barColor,
- label: "Th",
- },
- {
- value: 220,
- frontColor: barColor,
- label: "F",
- },
- {
- value: 160,
- frontColor: barColor,
- label: "Sa",
- },
- {
- value: 160,
- frontColor: barColor,
- label: "Su",
- },
- ];
+const UserChart = ({ profileData }: {
+ profileData: UserProfile | undefined;
+}) => {
+ const [dataList, setDataList] = useState([]);
+
+ const barColor = "#05a8b6";
+ useEffect(() => {
+ let weeklyDayPoints = profileData?.weeklyDayPoints || {
+ Monday: 0,
+ Tuesday: 0,
+ Wednesday: 0,
+ Thursday: 0,
+ Friday: 0,
+ Saturday: 0,
+ Sunday: 0,
+ };
+
+ // Sort by day
+ const sortedWeeklyPoints = Object.fromEntries(
+ weekOrder.map(day => [day, weeklyDayPoints[day]])
+ );
+
+ const data = Object.keys(sortedWeeklyPoints).map((day) => {
+ const value = weeklyDayPoints[day];
+
+ return {
+ value: value,
+ frontColor: barColor,
+ label: chartDayMap[day],
+ }
+ });
+ setDataList(data);
+ }, [])
return (
void;
-}) => {
+const PROGRESS_LIMIT = 5000;
+
+const UserChoresProgress = ({ setPageIndex }: { setPageIndex: (value: number) => void; }) => {
const [modalVisible, setModalVisible] = useState(false);
+ const { profileData, refreshProfileData } = useAuthContext();
+ const { mutateAsync: spendPoints } = useSpendPoints();
+
+ const allTimePoints = profileData?.allTimePoints ?? 0;
+ let transformedAllTimePoints = transformNumber(allTimePoints, PROGRESS_LIMIT);
+
+ useEffect(() => {
+ refreshProfileData();
+ }, [])
+
+ const onClickSpendPoints = (pointsToSpend: number) => {
+ if (allTimePoints < pointsToSpend) {
+ Alert.alert("Not Enough Points", "You do not have enough points to spend.");
+ return;
+ } else {
+ spendPoints(pointsToSpend).then(() => setModalVisible(false)).then(refreshProfileData);
+ }
+ }
+
return (
-
+
@@ -86,11 +105,11 @@ const UserChoresProgress = ({
text70
style={{fontFamily: "Manrope_600SemiBold", fontSize: 14}}
>
- You have 1200 points saved!
+ You have {allTimePoints} points saved!
0
- 5000
+ {PROGRESS_LIMIT}
@@ -114,12 +133,13 @@ const UserChoresProgress = ({
How would you like to spend your points?