diff options
Diffstat (limited to 'src/client/views/nodes/TaskBox.tsx')
-rw-r--r-- | src/client/views/nodes/TaskBox.tsx | 112 |
1 files changed, 2 insertions, 110 deletions
diff --git a/src/client/views/nodes/TaskBox.tsx b/src/client/views/nodes/TaskBox.tsx index 94252fafc..c99a91080 100644 --- a/src/client/views/nodes/TaskBox.tsx +++ b/src/client/views/nodes/TaskBox.tsx @@ -228,67 +228,13 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() { } /** - * Method to automatically sync the task to Google Tasks when the component loses focus - * @returns - a Promise that resolves when the sync is complete - */ - autoSyncToGoogle = async () => { - if (!this._needsSync && !this.Document.$googleTaskId) return; - await this.syncWithGoogleTaskBidirectional(); - - // if (!this._needsSync) return; - - // const token = await GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken(); - // if (!token) return; - - // runInAction(() => { - // this._syncing = true; - // }); - // const doc = this.Document; - // const taskTitle = StrCast(doc.title); - // const taskDesc = StrCast(doc[this.fieldKey]); - // const due = this.computeDueDate(); - // const isCompleted = !!doc.$task_completed; - - // const body = this.buildGoogleTaskBody(); - - // const isUpdate = !!doc.$googleTaskId; - // const endpoint = isUpdate ? `/googleTasks/${doc.$googleTaskId}` : '/googleTasks/create'; - // const method = isUpdate ? 'PATCH' : 'POST'; - - // const res = await fetch(endpoint, { - // method, - // credentials: 'include', - // headers: { - // 'Content-Type': 'application/json', - // Authorization: `Bearer ${token}`, - // }, - // body: JSON.stringify(body), - // }); - - // const result = await res.json(); - // if (result?.id) { - // runInAction(() => { - // this._lastSyncedTask = { title: taskTitle, text: taskDesc, due, completed: isCompleted }; - // this._needsSync = false; - // }); - // console.log('✅ Auto-synced with Google Tasks on blur'); - // } else { - // console.warn('❌ Auto-sync failed:', result); - // } - - // runInAction(() => { - // this._syncing = false; - // }); - }; - - /** - * Handles the blur event for the task box + * Handles the blur event for the task box (for auto-syncing) * @param e - the focus event */ handleBlur = (e: React.FocusEvent<HTMLDivElement>) => { // Check if focus is moving outside this component if (!e.currentTarget.contains(e.relatedTarget)) { - this.autoSyncToGoogle(); + this.syncWithGoogleTaskBidirectional(); } }; @@ -548,60 +494,6 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() { } else { alert('❌ Task sync failed.'); } - - // try { - // const token = await GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken(); - // if (!token) { - // const listener = () => { - // window.removeEventListener('focusin', listener); - // if (confirm('✅ Authorization complete. Try syncing the task again?')) { - // // you could refactor the click handler here - // handleGoogleTaskSync(); - // } - // window.removeEventListener('focusin', listener); - // }; - // setTimeout(() => window.addEventListener('focusin', listener), 100); - // return; - // } - - // this._syncing = true; - // const body = this.buildGoogleTaskBody(); - // const isUpdate = !!doc.$googleTaskId; - // const endpoint = isUpdate ? `/googleTasks/${doc.$googleTaskId}` : '/googleTasks/create'; - // const method = isUpdate ? 'PATCH' : 'POST'; - - // const response = await fetch(endpoint, { - // method, - // credentials: 'include', - // headers: { - // 'Content-Type': 'application/json', - // Authorization: `Bearer ${token}`, - // }, - // body: JSON.stringify(body), - // }); - - // const result = await response.json(); - // console.log('Google Task result:', result); - - // if (result?.id) { - // alert('✅ Task synced with Google Tasks!'); - // if (result?.id) { - // this._lastSyncedTask = { - // title: taskTitle, - // text: taskDesc, - // due, - // completed: isCompleted, - // }; - // runInAction(() => (this._needsSync = false)); - // } - // } else { - // alert(`❌ Failed: ${result?.error?.message || 'Unknown error'}`); - // } - // } catch (err) { - // console.error('Fetch error:', err); - // alert('❌ Task syncing failed.'); - // } - // this._syncing = false; }; return ( |