refresh stale data (#156)

This commit is contained in:
Doh
2025-05-30 18:04:03 -04:00
committed by GitHub
parent 1967d154ed
commit 276e8a8a7b
12 changed files with 396 additions and 66 deletions

View File

@@ -123,9 +123,27 @@ export const pomodoroAtom = atom<PomodoroAtom>({
minimized: false,
})
import { prepareDataForHashing, generateCryptoHash } from '@/lib/utils';
export const userSelectAtom = atom<boolean>(false)
export const aboutOpenAtom = atom<boolean>(false)
/**
* Asynchronous atom that calculates a freshness token (hash) based on the current client-side data.
* This token can be compared with a server-generated token to detect data discrepancies.
*/
export const clientFreshnessTokenAtom = atom(async (get) => {
const settings = get(settingsAtom);
const habits = get(habitsAtom);
const coins = get(coinsAtom);
const wishlist = get(wishlistAtom);
const users = get(usersAtom);
const dataString = prepareDataForHashing(settings, habits, coins, wishlist, users);
const hash = await generateCryptoHash(dataString);
return hash;
});
// Derived atom for completion cache
export const completionCacheAtom = atom((get) => {
const habits = get(habitsAtom).habits;