diff options
Diffstat (limited to 'src/client/views/nodes/TaskBox.tsx')
-rw-r--r-- | src/client/views/nodes/TaskBox.tsx | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/src/client/views/nodes/TaskBox.tsx b/src/client/views/nodes/TaskBox.tsx index c99a91080..5f46c9b2c 100644 --- a/src/client/views/nodes/TaskBox.tsx +++ b/src/client/views/nodes/TaskBox.tsx @@ -234,24 +234,39 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() { handleBlur = (e: React.FocusEvent<HTMLDivElement>) => { // Check if focus is moving outside this component if (!e.currentTarget.contains(e.relatedTarget)) { - this.syncWithGoogleTaskBidirectional(); + this.syncWithGoogleTaskBidirectional(true); } }; - syncWithGoogleTaskBidirectional = async (): Promise<boolean> => { + /** + * Method to sync the task with Google Tasks bidirectionally + * (update Dash from Google and vice versa, based on which is newer) + * @param silent - whether to suppress UI prompts to connect to Google (default: false) + * @returns - a promise that resolves to true if sync was successful, false otherwise + */ + + syncWithGoogleTaskBidirectional = async (silent = false): Promise<boolean> => { const doc = this.Document; - const token = await GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken(); + let token: string | undefined; + try { + token = silent ? await GoogleAuthenticationManager.Instance.fetchAccessTokenSilently() : await GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken(); + } catch (err) { + console.warn('Google auth failed:', err); + return false; + } if (!token) { - const listener = () => { - window.removeEventListener('focusin', listener); - if (confirm('✅ Authorization complete. Try syncing the task again?')) { - // you could refactor the click handler here - this.syncWithGoogleTaskBidirectional(); - } - window.removeEventListener('focusin', listener); - }; - setTimeout(() => window.addEventListener('focusin', listener), 100); + if (!silent) { + const listener = () => { + window.removeEventListener('focusin', listener); + if (confirm('✅ Authorization complete. Try syncing the task again?')) { + // you could refactor the click handler here + this.syncWithGoogleTaskBidirectional(); + } + window.removeEventListener('focusin', listener); + }; + setTimeout(() => window.addEventListener('focusin', listener), 100); + } return false; } @@ -373,7 +388,7 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() { console.warn('❌ Google Task creation failed:', result); } } catch (err) { - console.error('❌ Error creating Google Task:', err); + console.warn('❌ Error creating Google Task:', err); } } else if (doc.$googleTaskId) { await this.syncWithGoogleTaskBidirectional(); @@ -492,7 +507,7 @@ export class TaskBox extends ViewBoxBaseComponent<FieldViewProps>() { if (success) { alert('✅ Task successfully synced!'); } else { - alert('❌ Task sync failed.'); + alert('❌ Task sync failed. Try reloading.'); } }; |