fix: stale settings used when syncing books (#273)

* fix: add passive: true to touchstart event listener when pulling to refresh

* fix: stale settings used when syncing books and move auto upload from import menu to settings menu
This commit is contained in:
Huang Xin
2025-01-30 23:50:06 +01:00
committed by GitHub
parent 90e46860a5
commit b6c8bfb52b
4 changed files with 27 additions and 32 deletions
@@ -14,7 +14,7 @@ export const usePullToRefresh = (ref: React.RefObject<HTMLDivElement>, onTrigger
const el = ref.current;
if (!el) return;
el.addEventListener('touchstart', handleTouchStart);
el.addEventListener('touchstart', handleTouchStart, { passive: true });
function handleTouchStart(startEvent: TouchEvent) {
const el = ref.current;
@@ -22,7 +22,7 @@ export const usePullToRefresh = (ref: React.RefObject<HTMLDivElement>, onTrigger
const initialY = startEvent.touches[0]!.clientY;
el.addEventListener('touchmove', handleTouchMove);
el.addEventListener('touchmove', handleTouchMove, { passive: false });
el.addEventListener('touchend', handleTouchEnd);
function handleTouchMove(moveEvent: TouchEvent) {
+4
View File
@@ -94,6 +94,10 @@ export function useSync(bookKey?: string) {
if (!records?.length) return;
const maxTime = computeMaxTimestamp(records);
setLastSyncedAt(maxTime);
// due to closures in React hooks the settings might be stale
// we need to fetch the latest settings from store
const settings = useSettingsStore.getState().settings;
switch (type) {
case 'books':
settings.lastSyncedAtBooks = maxTime;