mirror of
https://github.com/urosran/cally.git
synced 2025-07-16 01:56:16 +00:00
- 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:
@ -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()];
|
||||
};
|
Reference in New Issue
Block a user