Fix corner case of sync progress failure (#187)

This commit is contained in:
Huang Xin
2025-01-17 13:45:29 +01:00
committed by GitHub
parent f64b5606f1
commit 5ca173818b
2 changed files with 16 additions and 8 deletions
@@ -29,6 +29,7 @@ export const useProgressSync = (bookKey: string) => {
const compressedConfig = JSON.parse(
serializeConfig(newConfig, settings.globalViewSettings, DEFAULT_BOOK_SEARCH_CONFIG),
);
delete compressedConfig.booknotes;
syncConfigs([compressedConfig], bookHash, 'push');
};
const pullConfig = (bookKey: string) => {
@@ -47,11 +48,11 @@ export const useProgressSync = (bookKey: string) => {
useEffect(() => {
if (!user) return;
pullConfig(bookKey);
return () => {
if (configSynced.current) {
pushConfig(bookKey, config);
}
};
// return () => {
// if (configSynced.current) {
// pushConfig(bookKey, config);
// }
// };
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+10 -3
View File
@@ -30,6 +30,8 @@ const computeMaxTimestamp = (records: BookDataRecord[]): number => {
return maxTime;
};
const SEVEN_DAYS_IN_MS = 7 * 24 * 60 * 60 * 1000;
export function useSync(bookKey?: string) {
const { settings } = useSettingsStore();
const { getConfig, setConfig } = useBookDataStore();
@@ -40,14 +42,19 @@ export function useSync(bookKey?: string) {
const [syncingNotes, setSyncingNotes] = useState(false);
const [syncError, setSyncError] = useState<string | null>(null);
const lastSyncedBooksAt = settings.lastSyncedAtBooks ?? 0;
const lastSyncedConfigsAt = config?.lastSyncedAtConfig ?? settings.lastSyncedAtConfigs ?? 0;
const lastSyncedNotesAt = config?.lastSyncedAtNotes ?? settings.lastSyncedAtNotes ?? 0;
const [lastSyncedAtBooks, setLastSyncedAtBooks] = useState<number>(
settings.lastSyncedAtBooks ?? 0,
lastSyncedBooksAt > 0 ? lastSyncedBooksAt - SEVEN_DAYS_IN_MS : 0,
);
const [lastSyncedAtConfigs, setLastSyncedAtConfigs] = useState<number>(
config?.lastSyncedAtConfig ?? settings.lastSyncedAtConfigs ?? 0,
lastSyncedConfigsAt > 0 ? lastSyncedConfigsAt - SEVEN_DAYS_IN_MS : 0,
);
const [lastSyncedAtNotes, setLastSyncedAtNotes] = useState<number>(
config?.lastSyncedAtNotes ?? settings.lastSyncedAtNotes ?? 0,
lastSyncedNotesAt > 0 ? lastSyncedNotesAt - SEVEN_DAYS_IN_MS : 0,
);
const [syncing, setSyncing] = useState(false);