aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/TaskBox.tsx
diff options
context:
space:
mode:
authorSkitty1238 <157652284+Skitty1238@users.noreply.github.com>2025-06-06 21:29:00 -0400
committerSkitty1238 <157652284+Skitty1238@users.noreply.github.com>2025-06-06 21:29:00 -0400
commitee7da91564ae293f394b487f96c53f0118af9d7b (patch)
tree953af327554b6d848447909cab0f55826425f04b /src/client/views/nodes/TaskBox.tsx
parent0c084cdc58c45c5315ff60f6a34f73fc722e25c9 (diff)
cleaned up popups so that not linking to Google doesnt bombard user with popups. Added debuggign instructions to alerts
Diffstat (limited to 'src/client/views/nodes/TaskBox.tsx')
-rw-r--r--src/client/views/nodes/TaskBox.tsx43
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.');
}
};