- Implemented saving of points per week per day for user

- Implemented saving of the number of completed todos per user
- Changed "To do's" labels to "To Do"
This commit is contained in:
Dejan
2024-12-25 22:41:53 +01:00
parent 406f541163
commit c14910447e
7 changed files with 38 additions and 9 deletions

View File

@ -255,7 +255,7 @@ export default function TabLayout() {
/>*/}
<DrawerButton
color="#8005eb"
title={"To Do's"}
title={"To Dos"}
bgColor={"#f3e6fd"}
pressFunc={() => {
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",
}}
/>
<Drawer.Screen

View File

@ -23,7 +23,7 @@ const ViewSwitch = memo(function ViewSwitch({ navigation }: ViewSwitchProps) {
<SegmentedControl
segments={[
{ label: "Calendar", segmentLabelStyle: styles.labelStyle },
{ label: "To Do's", segmentLabelStyle: styles.labelStyle },
{ label: "To Dos", segmentLabelStyle: styles.labelStyle },
]}
containerStyle={styles.segmentContainer}
style={styles.segment}

View File

@ -145,7 +145,7 @@ const MoveBrainDump = (props: {
style={styles.optionsIcon}
/>
<Text style={styles.optionsReg}>Move to</Text>
<Text style={styles.optionsBold}> my to do's</Text>
<Text style={styles.optionsBold}> my to dos</Text>
</View>
</TouchableOpacity>
<TouchableOpacity>

View File

@ -41,7 +41,7 @@ const ToDosPage = () => {
<View>
<View>
<HeaderTemplate
message="Here are your To Do's"
message="Here are your To Dos"
isWelcome={true}
link={profileData?.userType == ProfileType.PARENT && pageLink}
isToDos={true}

View File

@ -33,7 +33,7 @@ const FamilyChoresProgress = ({
style={{ fontFamily: "Poppins_400Regular", fontSize: 14.71 }}
color="#979797"
>
Return to To Do's
Return to To Dos
</Text>
</View>
</TouchableOpacity>
@ -123,7 +123,7 @@ const FamilyChoresProgress = ({
</Text>
<View centerV>
<Text style={{ fontSize: 15, fontFamily: "Manrope_700Bold" }}>
x/y chores completed
{`${child?.weeklyCompletedTodos ?? 0}/y chores completed`}
</Text>
</View>
</View>

View File

@ -44,5 +44,7 @@ export interface UserProfile {
microsoftAccounts?: { [email: string]: MicrosoftAccount };
appleAccounts?: { [email: string]: AppleAccount };
weeklyPoints?: number;
weeklyDayPoints?: Object;
allTimePoints?: number;
weeklyCompletedTodos?: number;
}

View File

@ -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);
});
@ -162,3 +183,9 @@ export const useUpdateTodo = () => {
}
})
};
const getCurrentDay = () => {
const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const now = new Date();
return days[now.getDay()];
};