Skip to content

Commit

Permalink
implement taskDoneToday colleciton cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaybadgujar102 committed Oct 18, 2024
1 parent 87852d3 commit 83a02c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/api/TasksDoneTodayAPI/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,25 @@ export const deleteTaskDoneToday = async (id: string) => {
export const deleteAllTasksDoneToday = async () => {
await db.tasksDoneTodayCollection.clear();
};

export const checkAndCleanupDoneTodayCollection = async () => {
const tasks = await getAllTasksDoneToday();

if (tasks.length === 0) {
return;
}

const firstTaskScheduledStart = new Date(tasks[0].scheduledStart);
const today = new Date();
const isSameDay = (date1: Date, date2: Date): boolean => {
return (
date1.getDate() === date2.getDate() &&
date1.getMonth() === date2.getMonth() &&
date1.getFullYear() === date2.getFullYear()
);
};

if (!isSameDay(firstTaskScheduledStart, today)) {
await deleteAllTasksDoneToday();
}
};
2 changes: 2 additions & 0 deletions src/hooks/useApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useSetRecoilState, useRecoilValue, useRecoilState } from "recoil";
import { scheduledHintCalls } from "@src/api/HintsAPI/ScheduledHintCall";
import { LocalStorageKeys } from "@src/constants/localStorageKeys";
import { checkAndCleanupTrash } from "@src/api/TrashAPI";
import { checkAndCleanupDoneTodayCollection } from "@src/api/TasksDoneTodayAPI";

const langFromStorage = localStorage.getItem(LocalStorageKeys.LANGUAGE)?.slice(1, -1);
const exceptionRoutes = ["/", "/invest", "/feedback", "/donate"];
Expand Down Expand Up @@ -147,6 +148,7 @@ function useApp() {

useEffect(() => {
checkAndCleanupTrash();
checkAndCleanupDoneTodayCollection();
}, []);

useEffect(() => {
Expand Down

0 comments on commit 83a02c4

Please sign in to comment.