From 0f997ee859c7540d7df0fe7fa7491f8933ab697f Mon Sep 17 00:00:00 2001 From: Skitty1238 <157652284+Skitty1238@users.noreply.github.com> Date: Thu, 5 Jun 2025 16:41:13 -0400 Subject: fixed automatically enabling/disabling sync button + persistence on reload --- src/client/views/nodes/TaskBox.tsx | 55 ++++++++++++++++++++------ src/server/ApiManagers/GeneralGoogleManager.ts | 44 ++++++++++----------- 2 files changed, 65 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/TaskBox.tsx b/src/client/views/nodes/TaskBox.tsx index 168e1455e..37f6124a1 100644 --- a/src/client/views/nodes/TaskBox.tsx +++ b/src/client/views/nodes/TaskBox.tsx @@ -23,6 +23,7 @@ export class TaskBox extends ViewBoxBaseComponent() { public static LayoutString(fieldStr: string) { return FieldView.LayoutString(TaskBox, fieldStr); } + // contains the last synced task information private _lastSyncedTask: { title: string; @@ -36,8 +37,23 @@ export class TaskBox extends ViewBoxBaseComponent() { completed: false, }; + // Whether the task needs to be synced with Google Tasks @observable _needsSync = false; + // Getter for needsSync + get needsSync() { + return this._needsSync; + } + + /** + * Constructor for the task box + * @param props - props containing the document reference + */ + constructor(props: FieldViewProps) { + super(props); + makeObservable(this); + } + /** * Method to update the task description * @param e - event of changing the description box input @@ -155,16 +171,6 @@ export class TaskBox extends ViewBoxBaseComponent() { this.Document.$task_completed = e.target.checked; }; - /** - * Constructor for the task box - * @param props - props containing the document reference - */ - - constructor(props: TaskBoxProps) { - super(props); - makeObservable(this); - } - _googleTaskCreateDisposer?: IReactionDisposer; _heightDisposer?: IReactionDisposer; _widthDisposer?: IReactionDisposer; @@ -241,6 +247,33 @@ export class TaskBox extends ViewBoxBaseComponent() { } ); + runInAction(() => { + const completed = BoolCast(doc.$task_completed); + const $task_allDay = BoolCast(doc.$task_allDay); + const endTime = DateCast(doc.$task_endTime); + const startTime = DateCast(doc.$task_startTime); + const datePart = StrCast(doc.$task_dateRange)?.split('|')[0]; + + const due = (() => { + if ($task_allDay && datePart && !isNaN(new Date(datePart).getTime())) { + return new Date(datePart).toISOString(); + } else if (endTime && !isNaN(+endTime.date)) { + return endTime.date.toISOString(); + } else if (startTime && !isNaN(+startTime.date)) { + return startTime.date.toISOString(); + } + return undefined; + })(); + + this._lastSyncedTask = { + title: StrCast(doc.title), + text: StrCast(doc[this.fieldKey]), + due, + completed, + }; + this._needsSync = false; + }); + this._googleTaskCreateDisposer = reaction( () => { const completed = BoolCast(doc.$task_completed); @@ -442,7 +475,7 @@ export class TaskBox extends ViewBoxBaseComponent() {