diff --git a/apps/readest-app/src/app/reader/hooks/useProgressSync.ts b/apps/readest-app/src/app/reader/hooks/useProgressSync.ts index f03da01a..dee3a823 100644 --- a/apps/readest-app/src/app/reader/hooks/useProgressSync.ts +++ b/apps/readest-app/src/app/reader/hooks/useProgressSync.ts @@ -134,11 +134,15 @@ export const useProgressSync = (bookKey: string) => { content?.index, bookData.bookDoc, ); - if (CFI.compare(remoteCFILocation, candidateCFI) < 0) { + if (!remoteCFILocation || CFI.compare(remoteCFILocation, candidateCFI) < 0) { remoteCFILocation = candidateCFI; } } - setConfig(bookKey, syncedConfig); + const filteredSyncedConfig = Object.fromEntries( + // eslint-disable-next-line @typescript-eslint/no-unused-vars + Object.entries(syncedConfig).filter(([_, value]) => value !== null && value !== undefined), + ); + setConfig(bookKey, { ...config, ...filteredSyncedConfig }); if (remoteCFILocation && configCFI) { if (CFI.compare(configCFI, remoteCFILocation) < 0) { if (view) { diff --git a/apps/readest-app/src/hooks/useSync.ts b/apps/readest-app/src/hooks/useSync.ts index 0d123b66..0762b9bc 100644 --- a/apps/readest-app/src/hooks/useSync.ts +++ b/apps/readest-app/src/hooks/useSync.ts @@ -33,6 +33,7 @@ const computeMaxTimestamp = (records: BookDataRecord[]): number => { return maxTime; }; +const ONE_DAY_IN_MS = 24 * 60 * 60 * 1000; export function useSync(bookKey?: string) { const router = useRouter(); const { settings, setSettings } = useSettingsStore(); @@ -77,10 +78,15 @@ export function useSync(bookKey?: string) { const lastSyncedConfigsAt = config?.lastSyncedAtConfig ?? settings.lastSyncedAtConfigs ?? 0; const lastSyncedNotesAt = config?.lastSyncedAtNotes ?? settings.lastSyncedAtNotes ?? 0; const now = Date.now(); - const fullSyncThreshold = 3 * 24 * 60 * 60 * 1000; - setLastSyncedAtBooks(now - lastSyncedBooksAt > fullSyncThreshold ? 0 : lastSyncedBooksAt); - setLastSyncedAtConfigs(now - lastSyncedConfigsAt > fullSyncThreshold ? 0 : lastSyncedConfigsAt); - setLastSyncedAtNotes(now - lastSyncedNotesAt > fullSyncThreshold ? 0 : lastSyncedNotesAt); + setLastSyncedAtBooks( + now - lastSyncedBooksAt > 3 * ONE_DAY_IN_MS ? 0 : lastSyncedBooksAt - ONE_DAY_IN_MS, + ); + setLastSyncedAtConfigs( + now - lastSyncedConfigsAt > 3 * ONE_DAY_IN_MS ? 0 : lastSyncedConfigsAt - ONE_DAY_IN_MS, + ); + setLastSyncedAtNotes( + now - lastSyncedNotesAt > 3 * ONE_DAY_IN_MS ? 0 : lastSyncedNotesAt - ONE_DAY_IN_MS, + ); setLastSyncedAtInited(true); // eslint-disable-next-line react-hooks/exhaustive-deps }, [bookKey, settings, config]);