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 ? (