diff options
author | Skitty1238 <157652284+Skitty1238@users.noreply.github.com> | 2025-06-05 11:25:20 -0400 |
---|---|---|
committer | Skitty1238 <157652284+Skitty1238@users.noreply.github.com> | 2025-06-05 11:25:20 -0400 |
commit | 87bd169df4a4384e41b32b3252b3b3c6618f4510 (patch) | |
tree | 16439af5a9759e8d7c8ce4fe02fb70725ef26dd6 | |
parent | c86bf5cc03d6fa59fbc11118d4e743d4c3064697 (diff) |
fixed being able to add tasks to Google Tasks. Cleaned up google authorization button clicks + alerts
-rw-r--r-- | src/client/apis/GoogleAuthenticationManager.tsx | 2 | ||||
-rw-r--r-- | src/client/views/nodes/TaskBox.tsx | 109 | ||||
-rw-r--r-- | src/server/apis/google/google_project_credentials.json | 7 |
3 files changed, 77 insertions, 41 deletions
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<object console.warn('Not linked yet or invalid JSON. open auth...'); // This is an auth URL — redirect the user to /refreshGoogle if (typeof response === 'string' && response.startsWith('http')) { - if (window.confirm('Authorize Dash to access your Google tasks?')) { + if (window.confirm('Authorize Dash to access your Google account?')) { window.open(response)?.focus(); return undefined; } diff --git a/src/client/views/nodes/TaskBox.tsx b/src/client/views/nodes/TaskBox.tsx index e755c6fe3..b59599052 100644 --- a/src/client/views/nodes/TaskBox.tsx +++ b/src/client/views/nodes/TaskBox.tsx @@ -211,9 +211,77 @@ export class TaskBox extends React.Component<TaskBoxProps> { 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 ( <div className="task-manager-container"> <input className="task-manager-title" type="text" placeholder="Task Title" value={taskTitle} onChange={this.updateTitle} disabled={isCompleted} style={{ opacity: isCompleted ? 0.7 : 1 }} /> @@ -257,44 +325,11 @@ export class TaskBox extends React.Component<TaskBoxProps> { <button className="task-manager-google" - onClick={async event => { + onClick={event => { event.preventDefault(); - - console.log('GT button clicked'); - try { - const token = await GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken(); - console.log('Got token', token); - - 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: allDay ? new Date(String(doc.$task_dateRange)?.split('|')[0]).toISOString() : (doc.$task_endTime instanceof DateField && doc.$task_endTime.date?.toISOString()) || undefined, - 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.'); - } + handleGoogleTaskClick(); }}> - Add to Google + Add to Google Tasks </button> </div> 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"] } } + |