From 87bd169df4a4384e41b32b3252b3b3c6618f4510 Mon Sep 17 00:00:00 2001 From: Skitty1238 <157652284+Skitty1238@users.noreply.github.com> Date: Thu, 5 Jun 2025 11:25:20 -0400 Subject: fixed being able to add tasks to Google Tasks. Cleaned up google authorization button clicks + alerts --- src/client/apis/GoogleAuthenticationManager.tsx | 2 +- src/client/views/nodes/TaskBox.tsx | 109 ++++++++++++++------- .../apis/google/google_project_credentials.json | 7 +- 3 files changed, 77 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/client/apis/GoogleAuthenticationManager.tsx b/src/client/apis/GoogleAuthenticationManager.tsx index 70e1ccc05..23e658329 100644 --- a/src/client/apis/GoogleAuthenticationManager.tsx +++ b/src/client/apis/GoogleAuthenticationManager.tsx @@ -101,7 +101,7 @@ export class GoogleAuthenticationManager extends ObservableReactComponent { const isCompleted = !!this.props.Document.$task_completed; const startTime = doc.$task_startTime instanceof DateField && doc.$task_startTime.date instanceof Date ? toLocalDateTimeString(doc.$task_startTime.date) : ''; - const endTime = doc.$task_endTime instanceof DateField && doc.$task_endTime.date instanceof Date ? toLocalDateTimeString(doc.$task_endTime.date) : ''; + const handleGoogleTaskClick = async () => { + console.log('GT button clicked'); + + try { + const token = await GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken(); + if (!token) { + const listener = () => { + window.removeEventListener('focusin', listener); + if (confirm('✅ Authorization complete. Try adding the task again?')) { + // you could refactor the click handler here + handleGoogleTaskClick(); + } + window.removeEventListener('focusin', listener); + }; + setTimeout(() => window.addEventListener('focusin', listener), 100); + return; + } + + let due: string | undefined; + + if (allDay) { + const rawRange = typeof doc.$task_dateRange === 'string' ? doc.$task_dateRange : ''; + const datePart = rawRange.split('|')[0]; + + if (datePart && !isNaN(new Date(datePart).getTime())) { + // Set time to midnight UTC to represent the start of the all-day event + const baseDate = datePart.includes('T') ? datePart : datePart + 'T00:00:00Z'; + due = new Date(baseDate).toISOString(); + } else { + due = undefined; + } + } else if (doc.$task_endTime instanceof DateField && doc.$task_endTime.date) { + due = doc.$task_endTime.date.toISOString(); + } else if (doc.$task_startTime instanceof DateField && doc.$task_startTime.date) { + due = doc.$task_startTime.date.toISOString(); + } else { + due = undefined; + } + + const response = await fetch('/googleTasks/create', { + method: 'POST', + credentials: 'include', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, + }, + body: JSON.stringify({ + title: taskTitle || 'Untitled Task', + notes: taskDesc, + due, + status: doc.$task_completed ? 'completed' : 'needsAction', + completed: doc.$task_completed ? new Date().toISOString() : undefined, + }), + }); + + const result = await response.json(); + console.log('Google Task result:', result); + + if (result?.id) { + alert('✅ Task sent to Google Tasks!'); + } else { + alert(`❌ Failed: ${result?.error?.message || 'Unknown error'}`); + } + } catch (err) { + console.error('Fetch error:', err); + alert('❌ Task creation failed.'); + } + }; + return (
@@ -257,44 +325,11 @@ export class TaskBox extends React.Component {
diff --git a/src/server/apis/google/google_project_credentials.json b/src/server/apis/google/google_project_credentials.json index 8abc13b80..8a9a38dac 100644 --- a/src/server/apis/google/google_project_credentials.json +++ b/src/server/apis/google/google_project_credentials.json @@ -1,11 +1,12 @@ { "installed": { - "client_id": "740987818053-dtflji3hfkn5r9t8ad6jb8740pls8moh.apps.googleusercontent.com", - "project_id": "dash-web-461920", + "client_id": "838617994486-a28072lirm8uk8cm78t7ic4krp0rgkgv.apps.googleusercontent.com", + "project_id": "gtasks-test-dash", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", - "client_secret": "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", + "client_secret": "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", "redirect_uris": ["http://localhost:1050/refreshGoogle"] } } + -- cgit v1.2.3-70-g09d2