- 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 <DrawerButton
color="#8005eb" color="#8005eb"
title={"To Do's"} title={"To Dos"}
bgColor={"#f3e6fd"} bgColor={"#f3e6fd"}
pressFunc={() => { pressFunc={() => {
props.navigation.navigate("todos"); props.navigation.navigate("todos");
@ -400,8 +400,8 @@ export default function TabLayout() {
drawerLabel: "To-Do", drawerLabel: "To-Do",
title: title:
Device.deviceType === DeviceType.TABLET Device.deviceType === DeviceType.TABLET
? "Family To Do's" ? "Family To Dos"
: "To Do's", : "To Dos",
}} }}
/> />
<Drawer.Screen <Drawer.Screen

View File

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

View File

@ -145,7 +145,7 @@ const MoveBrainDump = (props: {
style={styles.optionsIcon} style={styles.optionsIcon}
/> />
<Text style={styles.optionsReg}>Move to</Text> <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> </View>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity> <TouchableOpacity>

View File

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

View File

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

View File

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

View File

@ -130,16 +130,37 @@ export const useUpdateTodo = () => {
? userWeeklyPoints + todoUpdate.points ? userWeeklyPoints + todoUpdate.points
: 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; let userAllTimePoints = userData.allTimePoints ?? 0;
const allTimePoints = todoData.done const allTimePoints = todoData.done
? userAllTimePoints + todoUpdate.points ? userAllTimePoints + todoUpdate.points
: 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 // Update the user's points in Firestore
userData = { userData = {
...userData, ...userData,
weeklyPoints: weeklyPoints >= 0 ? weeklyPoints : 0, 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); 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()];
};