fix(config): prevent occasional errors when saving progress and configs (#2065)

This commit is contained in:
Huang Xin
2025-09-18 22:56:44 +08:00
committed by GitHub
parent 9727e4e9b8
commit e30a39f9cb
3 changed files with 11 additions and 11 deletions
@@ -21,7 +21,7 @@ const ReadingProgress: React.FC<ReadingProgressProps> = memo(
({ book }) => {
const progressPercentage = useMemo(() => getProgressPercentage(book), [book]);
if (progressPercentage === null) {
if (progressPercentage === null || Number.isNaN(progressPercentage)) {
return null;
}
@@ -13,10 +13,12 @@ export const useProgressAutoSave = (bookKey: string) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
const saveBookConfig = useCallback(
throttle(async () => {
const config = getConfig(bookKey)!;
const settings = useSettingsStore.getState().settings;
await saveConfig(envConfig, bookKey, config, settings);
throttle(() => {
setTimeout(async () => {
const config = getConfig(bookKey)!;
const settings = useSettingsStore.getState().settings;
await saveConfig(envConfig, bookKey, config, settings);
}, 5000);
}, 10000),
[],
);
+4 -6
View File
@@ -117,18 +117,16 @@ export function useSync(bookKey?: string) {
if (!bookId) {
settings.lastSyncedAtConfigs = maxTime;
setSettings(settings);
} else if (bookKey && config) {
config.lastSyncedAtConfig = maxTime;
setConfig(bookKey, config);
} else if (bookKey) {
setConfig(bookKey, { lastSyncedAtConfig: maxTime });
}
break;
case 'notes':
if (!bookId) {
settings.lastSyncedAtNotes = maxTime;
setSettings(settings);
} else if (bookKey && config) {
config.lastSyncedAtNotes = maxTime;
setConfig(bookKey, config);
} else if (bookKey) {
setConfig(bookKey, { lastSyncedAtNotes: maxTime });
}
break;
}