From 841b07596bc29389b836f430788d81878938bc3d Mon Sep 17 00:00:00 2001 From: Vinay Badgujar Date: Thu, 7 Nov 2024 16:36:10 +0530 Subject: [PATCH 1/4] feat: v1 of show scheduled status in edit modal --- .../GoalConfigModal/ConfigGoal.scss | 5 ++ .../GoalConfigModal/ConfigGoal.tsx | 65 +++++++++++++++++++ src/hooks/useScheduler.tsx | 18 +++++ 3 files changed, 88 insertions(+) diff --git a/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.scss b/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.scss index ed1f3d62c..d2e654010 100644 --- a/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.scss +++ b/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.scss @@ -156,3 +156,8 @@ gap: 10px; justify-content: center; } + +.schedule-status { + margin-top: 8px; + font-size: 14px; +} diff --git a/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx b/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx index 56541b32f..cea958c67 100644 --- a/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx +++ b/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx @@ -21,6 +21,8 @@ import { ILocationState } from "@src/Interfaces"; import { useLocation, useNavigate } from "react-router-dom"; import { suggestedGoalState } from "@src/store/SuggestedGoalState"; import { getHistoryUptoGoal } from "@src/helpers/GoalProcessor"; +import { ISchedulerOutput } from "@src/Interfaces/IScheduler"; +import useScheduler from "@src/hooks/useScheduler"; import { colorPalleteList, calDays, convertOnFilterToArray, getSelectedLanguage } from "../../../utils"; import "./ConfigGoal.scss"; @@ -277,8 +279,65 @@ const ConfigGoal = ({ type, goal, mode }: { type: TGoalCategory; mode: TGoalConf setHintOption(hint?.hintOptionEnabled || false); }; + const { checkGoalSchedule } = useScheduler(); + const titlePlaceholder = t(`${type !== "Budget" ? "goal" : "budget"}Title`); + type ScheduleStatus = "pending" | "scheduled" | "impossible" | "future" | null; + + const [scheduleStatus, setScheduleStatus] = useState(null); + + const checkSchedulingStatus = async (schedulerOutput: ISchedulerOutput | undefined, goalId: string) => { + if (!schedulerOutput) return "pending"; + + const { scheduled, impossible } = schedulerOutput; + + if (impossible?.some((task) => task.id === goalId)) { + return "impossible"; + } + + const isScheduledInNext7Days = scheduled.some((day) => day.tasks.some((task) => task.goalid === goalId)); + + return isScheduledInNext7Days ? "scheduled" : "future"; + }; + + const getScheduleStatusText = (status: ScheduleStatus) => { + switch (status) { + case "scheduled": + return "Auto scheduled"; + case "impossible": + return "! Impossible"; + case "future": + return "Scheduled someday"; + default: + return ""; + } + }; + + const checkSchedule = async () => { + // if (t) { + // setScheduleStatus(null); + // console.log("no duration"); + // return; + // } + + setScheduleStatus("pending"); + const schedulerOutput = await checkGoalSchedule(getFinalTags()); + console.log("schedulerOutput", schedulerOutput); + const status = await checkSchedulingStatus(schedulerOutput, goal.id); + console.log("status", status); + setScheduleStatus(status); + }; + + useEffect(() => { + const debounceTimer = setTimeout(() => { + console.log("checking schedule"); + checkSchedule(); + }, 1000); + + return () => clearTimeout(debounceTimer); + }, [tags.duration, afterTime, beforeTime, tags.on]); + return ( {t(`${action} Budget`)} + {scheduleStatus && ( +
{getScheduleStatusText(scheduleStatus)}
+ )} ) : ( @@ -425,6 +487,9 @@ const ConfigGoal = ({ type, goal, mode }: { type: TGoalCategory; mode: TGoalConf {t(`${action} Goal`)} + {scheduleStatus && ( +
{getScheduleStatusText(scheduleStatus)}
+ )}
{t("duration")} { + try { + const activeGoals: GoalItem[] = await getAllGoals(); + const goalsWithConfig = [...activeGoals, goal]; + + const { schedulerInput } = await organizeDataForInptPrep(goalsWithConfig); + + await init(); + const res = schedule(schedulerInput); + + return res; + } catch (error) { + console.log("Error checking goal schedule:", error); + return undefined; + } + }; + return { tasks, tasksStatus, setTasksStatus, + checkGoalSchedule, }; } From 2c5be17243b7f4339c62f5c3119760ef8a8c46d7 Mon Sep 17 00:00:00 2001 From: Vinay Badgujar Date: Sat, 9 Nov 2024 14:28:28 +0530 Subject: [PATCH 2/4] organize the code --- src/Interfaces/index.ts | 2 ++ .../GoalConfigModal/ConfigGoal.scss | 1 + .../GoalConfigModal/ConfigGoal.tsx | 29 +++++++------------ 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/Interfaces/index.ts b/src/Interfaces/index.ts index 41e81983d..7c0860a4e 100644 --- a/src/Interfaces/index.ts +++ b/src/Interfaces/index.ts @@ -33,3 +33,5 @@ export interface ILocationState { export interface ImpossibleGoal extends GoalItem { impossible: boolean; } + +export type ScheduleStatus = "pending" | "scheduled" | "impossible" | "future" | null; diff --git a/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.scss b/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.scss index d2e654010..89d30f086 100644 --- a/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.scss +++ b/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.scss @@ -160,4 +160,5 @@ .schedule-status { margin-top: 8px; font-size: 14px; + text-align: center; } diff --git a/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx b/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx index cea958c67..2f47f49a5 100644 --- a/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx +++ b/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx @@ -17,7 +17,7 @@ import { useParentGoalContext } from "@src/contexts/parentGoal-context"; import useGoalActions from "@src/hooks/useGoalActions"; import useGoalStore from "@src/hooks/useGoalStore"; import { unarchiveUserGoal } from "@src/api/GoalsAPI"; -import { ILocationState } from "@src/Interfaces"; +import { ILocationState, ScheduleStatus } from "@src/Interfaces"; import { useLocation, useNavigate } from "react-router-dom"; import { suggestedGoalState } from "@src/store/SuggestedGoalState"; import { getHistoryUptoGoal } from "@src/helpers/GoalProcessor"; @@ -49,6 +49,9 @@ const ConfigGoal = ({ type, goal, mode }: { type: TGoalCategory; mode: TGoalConf const location = useLocation(); const navigate = useNavigate(); + const { checkGoalSchedule } = useScheduler(); + const [scheduleStatus, setScheduleStatus] = useState(null); + let defaultColorIndex = Math.floor(Math.random() * colorPalleteList.length - 1) + 1; let defaultAfterTime = isEditMode ? (goal.afterTime ?? 9) : 9; let defaultBeforeTime = isEditMode ? (goal.beforeTime ?? 18) : 18; @@ -279,14 +282,8 @@ const ConfigGoal = ({ type, goal, mode }: { type: TGoalCategory; mode: TGoalConf setHintOption(hint?.hintOptionEnabled || false); }; - const { checkGoalSchedule } = useScheduler(); - const titlePlaceholder = t(`${type !== "Budget" ? "goal" : "budget"}Title`); - type ScheduleStatus = "pending" | "scheduled" | "impossible" | "future" | null; - - const [scheduleStatus, setScheduleStatus] = useState(null); - const checkSchedulingStatus = async (schedulerOutput: ISchedulerOutput | undefined, goalId: string) => { if (!schedulerOutput) return "pending"; @@ -315,12 +312,6 @@ const ConfigGoal = ({ type, goal, mode }: { type: TGoalCategory; mode: TGoalConf }; const checkSchedule = async () => { - // if (t) { - // setScheduleStatus(null); - // console.log("no duration"); - // return; - // } - setScheduleStatus("pending"); const schedulerOutput = await checkGoalSchedule(getFinalTags()); console.log("schedulerOutput", schedulerOutput); @@ -474,10 +465,10 @@ const ConfigGoal = ({ type, goal, mode }: { type: TGoalCategory; mode: TGoalConf - {scheduleStatus && ( -
{getScheduleStatusText(scheduleStatus)}
- )}
+ {scheduleStatus && ( +
{getScheduleStatusText(scheduleStatus)}
+ )} ) : (
@@ -487,9 +478,6 @@ const ConfigGoal = ({ type, goal, mode }: { type: TGoalCategory; mode: TGoalConf {t(`${action} Goal`)}
- {scheduleStatus && ( -
{getScheduleStatusText(scheduleStatus)}
- )}
{t("duration")}
+ {scheduleStatus && tags.duration && ( +
{getScheduleStatusText(scheduleStatus)}
+ )} )} From a0aae540e4e0f9705bdec78c2fa297368aa53baf Mon Sep 17 00:00:00 2001 From: Vinay Badgujar Date: Sat, 9 Nov 2024 14:50:13 +0530 Subject: [PATCH 3/4] add the day and week budget hours in checkSchedule effect dependency --- .../GoalsComponents/GoalConfigModal/ConfigGoal.tsx | 14 ++++++++------ src/hooks/useScheduler.tsx | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx b/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx index 2f47f49a5..23ef1c95f 100644 --- a/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx +++ b/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx @@ -313,11 +313,13 @@ const ConfigGoal = ({ type, goal, mode }: { type: TGoalCategory; mode: TGoalConf const checkSchedule = async () => { setScheduleStatus("pending"); - const schedulerOutput = await checkGoalSchedule(getFinalTags()); - console.log("schedulerOutput", schedulerOutput); - const status = await checkSchedulingStatus(schedulerOutput, goal.id); - console.log("status", status); - setScheduleStatus(status); + try { + const schedulerOutput = await checkGoalSchedule(getFinalTags()); + const status = await checkSchedulingStatus(schedulerOutput, goal.id); + setScheduleStatus(status); + } catch (error) { + setScheduleStatus(null); + } }; useEffect(() => { @@ -327,7 +329,7 @@ const ConfigGoal = ({ type, goal, mode }: { type: TGoalCategory; mode: TGoalConf }, 1000); return () => clearTimeout(debounceTimer); - }, [tags.duration, afterTime, beforeTime, tags.on]); + }, [tags.duration, afterTime, beforeTime, perDayHrs, perWeekHrs]); return ( Date: Sat, 16 Nov 2024 19:19:55 +0530 Subject: [PATCH 4/4] remove: setting explicit font size to schedule status --- src/components/GoalsComponents/GoalConfigModal/ConfigGoal.scss | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.scss b/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.scss index 89d30f086..727ce1fe9 100644 --- a/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.scss +++ b/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.scss @@ -159,6 +159,5 @@ .schedule-status { margin-top: 8px; - font-size: 14px; text-align: center; }