WIP: Web app transitions

This commit is contained in:
binwiederhier
2026-06-24 15:27:40 -04:00
parent 87e9dc9da4
commit 2b1f2d6b9a
15 changed files with 543 additions and 57 deletions
+33
View File
@@ -15,6 +15,39 @@ import notifier from "../app/Notifier";
import prefs from "../app/Prefs";
import { EVENT_MESSAGE_DELETE, EVENT_MESSAGE_CLEAR, SW_PERIODIC_SYNC_EXTEND_TOKEN_TAG } from "../app/events";
/**
* Reads a preference via a Dexie live query, but renders the last known value from localStorage
* synchronously on first paint (and mirrors new values back to localStorage). This avoids the
* Settings page flicker where rows "pop in" one by one while IndexedDB resolves -- the cached value
* shows instantly and is confirmed/updated from IndexedDB in the background.
*/
export const useCachedPref = (reader, cacheKey, fallback) => {
const live = useLiveQuery(reader);
useEffect(() => {
if (live !== undefined && live !== null) {
try {
localStorage.setItem(cacheKey, JSON.stringify(live));
} catch (e) {
// localStorage may be unavailable (private mode); the value just isn't cached for next time
}
}
}, [live, cacheKey]);
if (live !== undefined && live !== null) {
return live;
}
try {
const cached = localStorage.getItem(cacheKey);
if (cached !== null) {
return JSON.parse(cached);
}
} catch (e) {
// ignore parse/storage errors and fall back
}
return fallback;
};
/**
* Wire connectionManager and subscriptionManager so that subscriptions are updated when the connection
* state changes. Conversely, when the subscription changes, the connection is refreshed (which may lead