From 3fb0f7166bcb20c103f28546049c6dce4ecddf6e Mon Sep 17 00:00:00 2001 From: ManInDark <61268856+ManInDark@users.noreply.github.com> Date: Tue, 10 Mar 2026 16:41:26 +0100 Subject: [PATCH] fix(#2): state checking --- components/ClientWrapper.tsx | 5 ++--- components/UserSelectModal.tsx | 2 +- lib/atoms.ts | 10 ++++++++-- lib/constants.ts | 4 +++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/components/ClientWrapper.tsx b/components/ClientWrapper.tsx index b1adead..0f7824c 100644 --- a/components/ClientWrapper.tsx +++ b/components/ClientWrapper.tsx @@ -10,6 +10,7 @@ import LoadingSpinner from './LoadingSpinner'; import PomodoroTimer from './PomodoroTimer'; import RefreshBanner from './RefreshBanner'; import UserSelectModal from './UserSelectModal'; +import { DATA_FRESHNESS_INTERVAL } from '@/lib/constants'; function ClientWrapperContent({ children }: { children: ReactNode }) { const [pomo] = useAtom(pomodoroAtom) @@ -52,9 +53,7 @@ function ClientWrapperContent({ children }: { children: ReactNode }) { useEffect(() => { // Interval for polling data freshness if (clientToken && !showRefreshBanner && status === 'authenticated') { - const intervalId = setInterval(() => { - performFreshnessCheck(); - }, 30000); // Check every 30 seconds + const intervalId = setInterval(performFreshnessCheck, DATA_FRESHNESS_INTERVAL); return () => clearInterval(intervalId); } diff --git a/components/UserSelectModal.tsx b/components/UserSelectModal.tsx index 312ff30..2f5528c 100644 --- a/components/UserSelectModal.tsx +++ b/components/UserSelectModal.tsx @@ -128,7 +128,7 @@ export default function UserSelectModal({ onClose }: { onClose: () => void }) { const [isCreating, setIsCreating] = useState(false); const [isEditing, setIsEditing] = useState(false); const [error, setError] = useState(''); - const [usersData, setUsersData] = useAtom(usersAtom); + const [usersData] = useAtom(usersAtom); const users = usersData.users; const [currentUser] = useAtom(currentUserAtom); diff --git a/lib/atoms.ts b/lib/atoms.ts index 704bac5..da516bf 100644 --- a/lib/atoms.ts +++ b/lib/atoms.ts @@ -22,6 +22,7 @@ import { getDefaultWishlistData, Habit, PomodoroAtom, + User, UserId } from "./types"; @@ -77,6 +78,10 @@ export const currentUserAtom = atom((get) => { return users.users.find(user => user.id === currentUserId); }) +function removeHasPassword(users: Omit[]): Omit[] { + return users.map(user => { delete user.hasPassword; return user }); +} + /** * 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. @@ -86,9 +91,10 @@ export const clientFreshnessTokenAtom = atom(async (get) => { const habits = get(habitsAtom); const coins = get(coinsAtom); const wishlist = get(wishlistAtom); - const users = get(usersAtom); + const users = structuredClone(get(usersAtom)); + const usersWithoutHasPassword = removeHasPassword(users.users); - const dataString = prepareDataForHashing(settings, habits, coins, wishlist, users); + const dataString = prepareDataForHashing(settings, habits, coins, wishlist, { users: usersWithoutHasPassword }); const hash = await generateCryptoHash(dataString); return hash; }); diff --git a/lib/constants.ts b/lib/constants.ts index 12f025e..f2d39c5 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -33,4 +33,6 @@ export const QUICK_DATES = [ export const MAX_COIN_LIMIT = 9999 -export const DESKTOP_DISPLAY_ITEM_COUNT = 4 \ No newline at end of file +export const DESKTOP_DISPLAY_ITEM_COUNT = 4 + +export const DATA_FRESHNESS_INTERVAL = 30000; \ No newline at end of file