mirror of
https://github.com/ManInDark/HabitTrove.git
synced 2026-01-20 22:24:28 +01:00
refresh stale data (#156)
This commit is contained in:
18
lib/atoms.ts
18
lib/atoms.ts
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user