- Fixed incorrect saving of the points per day

This commit is contained in:
Dejan
2024-12-29 21:39:49 +01:00
parent ff81570e15
commit afa1046d02

View File

@ -139,7 +139,8 @@ export const useUpdateTodo = () => {
Saturday: 0,
Sunday: 0,
};
const currentDay = getCurrentDay();
const currentDay = getCurrentDay(todoUpdate.date);
const updatedPointsPerDay = todoData.done
? pointsPerDay[currentDay] + todoUpdate.points
: pointsPerDay[currentDay] - todoUpdate.points;
@ -158,7 +159,7 @@ export const useUpdateTodo = () => {
userData = {
...userData,
weeklyPoints: weeklyPoints >= 0 ? weeklyPoints : 0,
weeklyDayPoints: updatedPointsPerDay,
weeklyDayPoints: pointsPerDay,
allTimePoints: allTimePoints >= 0 ? allTimePoints : 0,
weeklyCompletedTodos: weeklyCompletedTodos >= 0 ? weeklyCompletedTodos : 0
}
@ -184,8 +185,8 @@ export const useUpdateTodo = () => {
})
};
const getCurrentDay = () => {
const getCurrentDay = (date) => {
let selectedDate = new Date(date.seconds * 1000);
const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const now = new Date();
return days[now.getDay()];
return days[selectedDate.getDay()];
};