Skip to content

Commit

Permalink
feat: skipped tasks are also added in doneTodayCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaybadgujar102 committed Oct 21, 2024
1 parent 3f3c129 commit 470ae54
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 39 deletions.
16 changes: 0 additions & 16 deletions src/api/TasksAPI/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,6 @@ export const refreshTaskCollection = async () => {
}
};

export const skipTask = async (id: string, period: string) => {
db.transaction("rw", db.taskCollection, async () => {
await db.taskCollection
.where("id")
.equals(id)
.modify((obj: TaskItem) => {
obj.skippedToday.push(period);
if (obj.skippedToday.length > 1) {
obj.skippedToday.sort((a, b) => Number(a.split("-")[0]) - Number(b.split("-")[0]));
}
});
}).catch((e) => {
console.log(e.stack || e);
});
};

export const getAllTasks = async () => {
const allGoals = await db.taskCollection.toArray();
allGoals.reverse();
Expand Down
33 changes: 27 additions & 6 deletions src/api/TasksDoneTodayAPI/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,43 @@ import { db } from "@src/models";
import { TasksDoneTodayItem } from "@src/models/TasksDoneTodayItem";

export const addTaskDoneToday = async (completedTask: TasksDoneTodayItem) => {
await db.tasksDoneTodayCollection.add(completedTask);
try {
await db.tasksDoneTodayCollection.add(completedTask);
} catch (error) {
console.error("Error adding task:", error);
}
};

export const getAllTasksDoneToday = async () => {
const tasks = await db.tasksDoneTodayCollection.toArray();
return tasks;
try {
const tasks = await db.tasksDoneTodayCollection.toArray();
return tasks;
} catch (error) {
console.error("Error fetching tasks:", error);
return [];
}
};

export const deleteTaskDoneToday = async (id: string) => {
await db.tasksDoneTodayCollection.delete(id);
try {
await db.tasksDoneTodayCollection.delete(id);
} catch (error) {
console.error("Error deleting task:", error);
}
};

export const deleteTasksDoneTodayByGoalId = async (goalId: string) => {
await db.tasksDoneTodayCollection.where("goalId").equals(goalId).delete();
try {
await db.tasksDoneTodayCollection.where("goalId").equals(goalId).delete();
} catch (error) {
console.error("Error deleting tasks by goalId:", error);
}
};

export const deleteAllTasksDoneToday = async () => {
await db.tasksDoneTodayCollection.clear();
try {
await db.tasksDoneTodayCollection.clear();
} catch (error) {
console.error("Error clearing tasks:", error);
}
};
8 changes: 3 additions & 5 deletions src/components/MyTimeComponents/MyTimeline/MyTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ export const MyTimeline: React.FC<MyTimelineProps> = ({ day, myTasks, doneTasks
if (actionName === TaskAction.Done) {
return handleDoneClick(task);
}
if (actionName === TaskAction.NotNow) {
return setOpenReschedule({ ...task });
}
if (day === "Today") {
const taskItem = await getTaskByGoalId(task.goalid);
if (!taskItem) {
Expand All @@ -119,11 +122,6 @@ export const MyTimeline: React.FC<MyTimelineProps> = ({ day, myTasks, doneTasks
hoursSpent: 0,
blockedSlots: [],
});
} else if (actionName === TaskAction.NotNow) {
setOpenReschedule(task);
}
if (actionName === TaskAction.NotNow) {
setOpenReschedule({ ...task });
}
} else {
setShowToast({ open: true, message: "Let's focus on Today :)", extra: "" });
Expand Down
16 changes: 8 additions & 8 deletions src/components/MyTimeComponents/NotNow/NotNowModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import React, { useEffect, useState } from "react";
import { lastAction } from "@src/store";
import "./NotNowModal.scss";
import ZModal from "@src/common/ZModal";
import { addBlockedSlot, getTaskByGoalId, skipTask } from "@src/api/TasksAPI"; // Assume getGoalById exists
import { addBlockedSlot } from "@src/api/TasksAPI";
import { displayReschedule } from "@src/store/TaskState";
import { MILLISECONDS_IN_HOUR, RESCHEDULE_OPTIONS } from "@src/constants/rescheduleOptions";
import { convertDateToString } from "@src/utils";
import ActionDiv from "@components/GoalsComponents/MyGoalActions/ActionDiv";
import { getGoalById } from "@src/api/GoalsAPI";
import { getHrFromDateString } from "@src/utils/SchedulerUtils";
import forgetTune from "@assets/forget.mp3";
import { addTaskActionEvent } from "@src/api/TaskHistoryAPI";
import { addTaskDoneToday } from "@src/api/TasksDoneTodayAPI";

const NotNowModal = () => {
const [task, setDisplayReschedule] = useRecoilState(displayReschedule);
Expand Down Expand Up @@ -55,12 +55,12 @@ const NotNowModal = () => {
};

const handleSkip = async () => {
const taskItem = await getTaskByGoalId(task.goalid);
if (!taskItem) {
return;
}
const period = `${getHrFromDateString(task.start)}-${getHrFromDateString(task.deadline)}`;
await skipTask(taskItem?.id, period);
await addTaskDoneToday({
scheduledTaskId: task.taskid,
scheduledStart: task.start,
scheduledEnd: task.deadline,
goalId: task.goalid,
});
await addTaskActionEvent(task, "skipped");
setDisplayReschedule(null);
setLastAction("TaskSkipped");
Expand Down
2 changes: 0 additions & 2 deletions src/controllers/TaskDoneTodayController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { addTaskDoneToday, deleteAllTasksDoneToday, getAllTasksDoneToday } from "@src/api/TasksDoneTodayAPI";
import { v4 as uuidv4 } from "uuid";

export const completeTask = async (
scheduledTaskId: string,
Expand All @@ -9,7 +8,6 @@ export const completeTask = async (
) => {
try {
await addTaskDoneToday({
id: uuidv4(),
scheduledTaskId,
goalId,
scheduledStart,
Expand Down
1 change: 0 additions & 1 deletion src/models/TasksDoneTodayItem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export interface TasksDoneTodayItem {
id: string;
scheduledTaskId: string;
goalId: string;
scheduledStart: string;
Expand Down
2 changes: 1 addition & 1 deletion src/models/dexie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const dbStoreSchema = {
impossibleGoalsCollection: "goalId, goalTitle",
schedulerOutputCacheCollection: "id, key, value",
taskHistoryCollection: "++id, goalId, eventType, eventTime, scheduledStart, scheduledEnd, duration",
tasksDoneTodayCollection: "id, goalId, scheduledStart, scheduledEnd",
tasksDoneTodayCollection: "++id, goalId, scheduledStart, scheduledEnd",
};
export const syncVersion = (transaction: Transaction, currentVersion: number) => {
if (currentVersion < 9) {
Expand Down

0 comments on commit 470ae54

Please sign in to comment.