This commit is contained in:
Timothy Jaeryang Baek
2026-01-01 03:03:10 +04:00
parent a1036e544d
commit b67796465e
@@ -59,7 +59,6 @@
window.removeEventListener('message', handleMessage); window.removeEventListener('message', handleMessage);
}); });
// State // State
let syncing = false; let syncing = false;
let downloading = false; let downloading = false;
@@ -78,15 +77,13 @@
let syncMode: 'incremental' | 'full' = 'incremental'; let syncMode: 'incremental' | 'full' = 'incremental';
// Reactive progress percentage // Reactive progress percentage
$: progressPercent = total > 0 ? Math.min(Math.round((processedItemsCount / total) * 100), 100) : 0; $: progressPercent =
total > 0 ? Math.min(Math.round((processedItemsCount / total) * 100), 100) : 0;
// Helper to send postMessage to opener // Helper to send postMessage to opener
const postToOpener = (message: object) => { const postToOpener = (message: object) => {
if (window.opener) { if (window.opener) {
window.opener.postMessage( window.opener.postMessage({ ...message, requestId: eventData?.requestId ?? null }, '*');
{ ...message, requestId: eventData?.requestId ?? null },
'*'
);
} }
}; };
@@ -120,6 +117,8 @@
} }
syncing = false; syncing = false;
downloading = false; downloading = false;
postToOpener({ type: 'sync:error', error: 'User cancelled the operation' });
}; };
// Sync stats to opener window // Sync stats to opener window
@@ -157,11 +156,7 @@
searchParams.updated_at = eventData.lastSyncedChatUpdatedAt; searchParams.updated_at = eventData.lastSyncedChatUpdatedAt;
} }
const res = await exportChatStats( const res = await exportChatStats(localStorage.token, page, searchParams).catch((err) => {
localStorage.token,
page,
searchParams
).catch((err) => {
throw new Error(err?.detail || err?.message || 'Failed to export chat stats'); throw new Error(err?.detail || err?.message || 'Failed to export chat stats');
}); });
@@ -211,11 +206,7 @@
try { try {
// Get total count first (no filters for download - get all) // Get total count first (no filters for download - get all)
const initialRes = await exportChatStats( const initialRes = await exportChatStats(localStorage.token, 1, {}).catch(() => null);
localStorage.token,
1,
{}
).catch(() => null);
if (initialRes?.total) { if (initialRes?.total) {
total = initialRes.total; total = initialRes.total;
@@ -235,7 +226,9 @@
localStorage.token, localStorage.token,
searchParams.updated_at searchParams.updated_at
).catch((err) => { ).catch((err) => {
throw new Error(err?.detail || 'Failed to connect to the server. Please check your connection.'); throw new Error(
err?.detail || 'Failed to connect to the server. Please check your connection.'
);
}); });
if (!res) { if (!res) {
@@ -404,16 +397,23 @@
{#if eventData?.lastSyncedChatUpdatedAt} {#if eventData?.lastSyncedChatUpdatedAt}
<div class="mt-3"> <div class="mt-3">
<Tooltip content={$i18n.t('Syncs only chats with updates after your last sync timestamp. Disable to re-sync all chats.')} placement="top-start"> <Tooltip
content={$i18n.t(
'Syncs only chats with updates after your last sync timestamp. Disable to re-sync all chats.'
)}
placement="top-start"
>
<label class="flex items-center gap-2 text-xs cursor-pointer"> <label class="flex items-center gap-2 text-xs cursor-pointer">
<input <input
type="checkbox" type="checkbox"
checked={syncMode === 'incremental'} checked={syncMode === 'incremental'}
on:change={(e) => syncMode = e.target.checked ? 'incremental' : 'full'} on:change={(e) => (syncMode = e.target.checked ? 'incremental' : 'full')}
disabled={syncing} disabled={syncing}
class="w-4 h-4 rounded border-gray-300 dark:border-gray-600" class="w-4 h-4 rounded border-gray-300 dark:border-gray-600"
/> />
<span class="text-gray-700 dark:text-gray-300">{$i18n.t('Only sync new/updated chats')}</span> <span class="text-gray-700 dark:text-gray-300"
>{$i18n.t('Only sync new/updated chats')}</span
>
</label> </label>
</Tooltip> </Tooltip>
</div> </div>
@@ -428,8 +428,6 @@
<div> <div>
{#if total > 0} {#if total > 0}
{processedItemsCount}/{total} {processedItemsCount}/{total}
{:else}
{processedItemsCount}
{/if} {/if}
</div> </div>
</div> </div>
@@ -440,7 +438,9 @@
style="width: {progressPercent}%" style="width: {progressPercent}%"
></div> ></div>
{:else} {:else}
<div class="bg-gray-900 dark:bg-gray-100 h-1.5 w-1/3 rounded-full animate-pulse"></div> <div
class="bg-gray-900 dark:bg-gray-100 h-1.5 w-0 rounded-full animate-pulse"
></div>
{/if} {/if}
</div> </div>
</div> </div>