From b3f1d10bc1614e5b7219924d590cbbd01b4110fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Padez?= Date: Sun, 22 Mar 2026 17:07:06 +0000 Subject: [PATCH] inline email resync instead of job queue, refresh list on completion Co-Authored-By: Claude Opus 4.6 (1M context) --- .../Screens/Dashboard/Email/EmailList.tsx | 24 +- .../IntegrationsSettings/EmailAccounts.tsx | 14 +- src/servers/api/email/accounts.ts | 32 +- src/servers/api/email/resync.ts | 296 ++++++++++++++++++ src/servers/queue/handlers/gmail-sync.ts | 10 +- src/servers/sidecar/email/email-cron.ts | 72 +---- src/servers/sidecar/email/index.ts | 2 +- 7 files changed, 367 insertions(+), 83 deletions(-) create mode 100644 src/servers/api/email/resync.ts diff --git a/src/apps/officer-web/Screens/Dashboard/Email/EmailList.tsx b/src/apps/officer-web/Screens/Dashboard/Email/EmailList.tsx index 99e7fa47..3b92cede 100644 --- a/src/apps/officer-web/Screens/Dashboard/Email/EmailList.tsx +++ b/src/apps/officer-web/Screens/Dashboard/Email/EmailList.tsx @@ -73,18 +73,28 @@ export const EmailList = () => { setPage(1); }; + const [syncing, setSyncing] = useState(false); + const handleSync = async () => { if (!syncableAccount) return; + setSyncing(true); try { - await client.post(`/email/accounts/${syncableAccount.id}/sync`, {}); - toast.success('Sync started'); + const result = await client.post<{ ok: boolean; saved?: number }>(`/email/accounts/${syncableAccount.id}/sync`, {}); + if (result.saved !== undefined) { + toast.success(result.saved > 0 ? `${result.saved} new emails` : 'No new emails'); + queryClient.invalidateQueries({ queryKey: ['email-messages'] }); + } else { + toast.success('Sync started'); + } refetchAccounts(); } catch (err) { - toast.error(err instanceof Error ? err.message : 'Failed to start sync'); + toast.error(err instanceof Error ? err.message : 'Failed to sync'); + } finally { + setSyncing(false); } }; - // Poll accounts while syncing, refresh email list when done + // Poll accounts while first sync is running (job-based), refresh email list when done const prevSyncing = useRef(false); useEffect(() => { if (isSyncing) { @@ -149,8 +159,8 @@ export const EmailList = () => { ) : syncableAccount ? (
No emails synced yet -
@@ -189,7 +199,7 @@ export const EmailList = () => { })} {total} - {isSyncing ? ( + {syncing || isSyncing ? ( ) : syncableAccount ? (