From 09d1e0c04006b697b0a8f6b9fb5935c9b239baec Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Sun, 5 Apr 2026 23:55:41 +0800 Subject: [PATCH] fix(sync): show last push time as the last sync time (#3760) --- .../src/app/reader/components/ViewMenu.tsx | 7 ++++++- apps/readest-app/src/hooks/useSync.ts | 14 +++++++++++--- apps/readest-app/src/types/book.ts | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/apps/readest-app/src/app/reader/components/ViewMenu.tsx b/apps/readest-app/src/app/reader/components/ViewMenu.tsx index ed9d87c6..320f7a24 100644 --- a/apps/readest-app/src/app/reader/components/ViewMenu.tsx +++ b/apps/readest-app/src/app/reader/components/ViewMenu.tsx @@ -157,7 +157,12 @@ const ViewMenu: React.FC = ({ bookKey, setIsDropdownOpen }) => { // eslint-disable-next-line react-hooks/exhaustive-deps }, [keepCoverSpread]); - const lastSyncTime = Math.max(config?.lastSyncedAtConfig || 0, config?.lastSyncedAtNotes || 0); + const lastSyncTime = Math.max( + config?.lastSyncedAtConfig || 0, + config?.lastSyncedAtNotes || 0, + config?.lastPushedAtConfig || 0, + config?.lastPushedAtNotes || 0, + ); return ( { + const pushChanges = async (payload: SyncData): Promise => { setSyncing(true); setSyncError(null); try { const result = await syncClient.pushChanges(payload); setSyncResult(result); + return true; } catch (err: unknown) { console.error(err); if (err instanceof Error) { @@ -174,6 +175,7 @@ export function useSync(bookKey?: string) { } else { setSyncError('Error pushing changes'); } + return false; } finally { setSyncing(false); } @@ -203,7 +205,10 @@ export function useSync(bookKey?: string) { async (bookConfigs?: BookConfig[], bookId?: string, metaHash?: string, op: SyncOp = 'both') => { if (!bookId && !lastSyncedAtInited) return; if ((op === 'push' || op === 'both') && bookConfigs?.length) { - await pushChanges({ configs: bookConfigs }); + const pushed = await pushChanges({ configs: bookConfigs }); + if (pushed && bookId && bookKey) { + setConfig(bookKey, { lastPushedAtConfig: Date.now() }); + } } if (op === 'pull' || op === 'both') { await pullChanges( @@ -224,7 +229,10 @@ export function useSync(bookKey?: string) { async (bookNotes?: BookNote[], bookId?: string, metaHash?: string, op: SyncOp = 'both') => { if (!lastSyncedAtInited) return; if ((op === 'push' || op === 'both') && bookNotes?.length) { - await pushChanges({ notes: bookNotes }); + const pushed = await pushChanges({ notes: bookNotes }); + if (pushed && bookId && bookKey) { + setConfig(bookKey, { lastPushedAtNotes: Date.now() }); + } } if (op === 'pull' || op === 'both') { await pullChanges( diff --git a/apps/readest-app/src/types/book.ts b/apps/readest-app/src/types/book.ts index 454be23b..ec40319b 100644 --- a/apps/readest-app/src/types/book.ts +++ b/apps/readest-app/src/types/book.ts @@ -372,6 +372,8 @@ export interface BookConfig { lastSyncedAtConfig?: number; lastSyncedAtNotes?: number; + lastPushedAtConfig?: number; + lastPushedAtNotes?: number; foliateImportedAt?: number; // Per-book switch for hardcover exports in reader menu.