Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed unused properties from TaskItem interface (#2065) #2066

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Interfaces/IScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ export interface ISchedulerInputGoal {
};
children?: string[];
createdAt: string;
hoursSpent?: number;
skippedToday?: string[];
}

export interface ISchedulerOutputGoal {
Expand Down
42 changes: 1 addition & 41 deletions src/api/TasksAPI/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,12 @@ export const getTaskByGoalId = async (goalId: string) => {
}
};

export const getForgetHrsCount = (task: TaskItem) => {
let yesterdaysCount = 0;
task.skippedToday.forEach((slot) => {
const [start, end] = slot.split("-");
yesterdaysCount += Number(end) - Number(start);
});
return yesterdaysCount;
};

export const resetProgressOfToday = async () => {
const tasks = await db.taskCollection.toArray();
try {
await db.transaction("rw", db.taskCollection, async () => {
const updatedRows = tasks.map((_task) => {
const task = { ..._task };
task.completedToday = 0;
task.completedTodayIds = [];
task.skippedToday = [];
task.lastCompleted = new Date().toLocaleDateString();
task.lastSkipped = new Date().toLocaleDateString();
task.blockedSlots = [];
return task;
});
Expand All @@ -74,28 +60,8 @@ export const refreshTaskCollection = async () => {
const updatedRows = tasks.map((_task) => {
const task = { ..._task };
const goal: GoalItem = goals[task.goalId];
const startDate = new Date(goal.start || goal.createdAt);
if (goal.habit === "daily") {
task.hoursSpent = 0;
} else if (goal.habit === "weekly") {
const dayIndex = calDays.indexOf(convertDateToDay(startDate));
const lastReset = getLastDayDate(dayIndex);
const lastAction = new Date(
new Date(task.lastSkipped) < new Date(task.lastCompleted) ? task.lastCompleted : task.lastSkipped,
);
if (lastAction < lastReset) {
task.hoursSpent = 0;
} else {
task.hoursSpent += task.completedToday + getForgetHrsCount(task);
}
} else {
task.hoursSpent += task.completedToday + getForgetHrsCount(task);
if (goal.habit === "weekly") {
}
task.completedToday = 0;
task.completedTodayIds = [];
task.skippedToday = [];
task.lastCompleted = new Date().toLocaleDateString();
task.lastSkipped = new Date().toLocaleDateString();
return task;
});

Expand All @@ -112,13 +78,11 @@ export const completeTask = async (id: string, duration: number, task: ITask) =>
.where("id")
.equals(id)
.modify((obj: TaskItem) => {
obj.completedToday += duration;
obj.completedTodayTimings.push({
goalid: task.goalid,
start: task.start,
deadline: task.deadline,
});
obj.completedTodayIds.push(task.taskid);
});
}).catch((e) => {
console.log(e.stack || e);
Expand All @@ -131,15 +95,11 @@ export const skipTask = async (id: string, period: string, task: ITask) => {
.where("id")
.equals(id)
.modify((obj: TaskItem) => {
obj.skippedToday.push(period);
obj.completedTodayTimings.push({
goalid: task.goalid,
start: task.start,
deadline: task.deadline,
});
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);
Expand Down
8 changes: 0 additions & 8 deletions src/components/MyTimeComponents/MyTimeline/MyTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ export const MyTimeline: React.FC<MyTimelineProps> = ({ day, myTasks, taskDetail
id: uuidv4(),
goalId: task.goalid,
title: task.title,
completedTodayIds: [],
skippedToday: [],
completedToday: actionName === TaskAction.Done ? Number(task.duration) : 0,
lastSkipped: "",
lastCompleted: actionName === TaskAction.Done ? new Date().toLocaleDateString() : "",
hoursSpent: 0,
completedTodayTimings:
actionName === TaskAction.Done
? [
Expand All @@ -124,8 +118,6 @@ export const MyTimeline: React.FC<MyTimelineProps> = ({ day, myTasks, taskDetail
blockedSlots: [],
});
} else if (actionName === TaskAction.Done) {
const markDone = !!taskDetails[task.goalid]?.completedTodayIds.includes(task.taskid);
if (markDone) return null;
await completeTask(taskItem.id, Number(task.duration), task);
} else if (actionName === TaskAction.NotNow) {
setOpenReschedule(task);
Expand Down
5 changes: 0 additions & 5 deletions src/helpers/MyTimeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export const transformIntoSchInputGoals = (
activeGoals.forEach(async (ele) => {
const obj: ISchedulerInputGoal = { id: ele.id, title: t(ele.title), filters: {}, createdAt: ele.createdAt };
const slotsNotallowed = blockedSlots[ele.id];
// obj.hoursSpent = dbTasks[ele.id]?.hoursSpent || 0;
// obj.skippedToday = dbTasks[ele.id]?.skippedToday || [];
if (ele.duration) obj.minDuration = Number(ele.duration);
if (ele.start) {
obj.start = convertDateToString(new Date(ele.start));
Expand Down Expand Up @@ -154,9 +152,6 @@ export const organizeDataForInptPrep = async (inputGoals: GoalItem[]) => {
const startDate = convertDateToString(new Date(_today));
const endDate = convertDateToString(new Date(_today.setDate(_today.getDate() + 7)));
const tasksCompletedToday: TCompletedTaskTiming[] = [];
getAllTasks().then((docs) =>
docs.filter((doc) => doc.completedToday > 0).map((doc) => tasksCompletedToday.push(...doc.completedTodayTimings)),
);

const schedulerInput: ISchedulerInput = {
startDate,
Expand Down
6 changes: 0 additions & 6 deletions src/models/TaskItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ export interface TaskItem {
id: string;
goalId: string;
title: string;
hoursSpent: number;
completedToday: number;
completedTodayIds: string[];
skippedToday: string[];
lastCompleted: string; // date
lastSkipped: string; // date
blockedSlots: blockedSlotOfTask[];
completedTodayTimings: TCompletedTaskTiming[]; // to store timings of the tasks that are completed today
}
6 changes: 1 addition & 5 deletions src/models/dexie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export const dbStoreSchema = {
inboxCollection: "id, goalChanges",
pubSubCollection: "id, subscribers",
publicGroupsCollection: null,
taskCollection:
"id, goalId, title, hoursSpent, completedTodayIds, completedTodayTimings, lastCompleted, lastSkipped, blockedSlots, skippedToday, completedToday",
taskCollection: "id, goalId, title, completedTodayTimings, blockedSlots",
customizationCollection: "++id, goalId, posIndex",
dumpboxCollection: "id, key, value",
partnersCollection: null,
Expand Down Expand Up @@ -46,9 +45,6 @@ export const syncVersion = (transaction: Transaction, currentVersion: number) =>
const taskCollection = transaction.table("taskCollection");
taskCollection.toCollection().modify((task: TaskItem) => {
task.blockedSlots = [];
task.skippedToday = [];
task.completedToday = 0;
task.completedTodayIds = [];
});
}
if (currentVersion < 12) {
Expand Down
3 changes: 0 additions & 3 deletions src/utils/rawDBScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
// const data = event.target.result;

// // Modify the desired field(s)
// data.lastCompleted = "5/5/2023";
// data.lastSkipped = "5/5/2023";
// data.hoursSpent = 5;

// // Put the modified data back into the object store
// const putRequest = objectStore.put(data);
Expand Down
Loading