diff --git a/src/common/hooks/useRemote.ts b/src/common/hooks/useRemote.ts index b2ca43f..81897a6 100644 --- a/src/common/hooks/useRemote.ts +++ b/src/common/hooks/useRemote.ts @@ -1,8 +1,10 @@ import { useEffect, useReducer, useState, type Dispatch, type Reducer, type StateUpdater } from "preact/hooks"; import { loadObject, saveObject } from "@common/storage"; +declare const GAME: string; + export const useRemoteState = (key: string, initialValue: T) => { - const storedKey = `useRemoteState.${key}`; + const storedKey = `useRemoteState.${GAME}.${key}`; const [value, setValue] = useState(initialValue); @@ -33,7 +35,7 @@ const wrapReducer = (reducer: Reducer): Reducer(key: string, reducer: Reducer, initialValue: T) => { - const storedKey = `useRemoteReducer.${key}`; + const storedKey = `useRemoteReducer.${GAME}.${key}`; const [state, dispatch] = useReducer(wrapReducer(reducer), initialValue); diff --git a/src/common/hooks/useStored.ts b/src/common/hooks/useStored.ts index 7a40b7e..ad7fafc 100644 --- a/src/common/hooks/useStored.ts +++ b/src/common/hooks/useStored.ts @@ -1,7 +1,9 @@ import { useEffect, useReducer, useState, type Dispatch, type Reducer, type StateUpdater } from "preact/hooks"; +declare const GAME: string; + export const useStoredState = (key: string, initialValue: T) => { - const storedKey = `useStoredState.${key}`; + const storedKey = `useStoredState.${GAME}.${key}`; const [value, setValue] = useState(() => { try { @@ -20,7 +22,7 @@ export const useStoredState = (key: string, initialValue: T) => { }; export const useStoredReducer = (key: string, reducer: Reducer, initialValue: T) => { - const storedKey = `useStoredReducer.${key}`; + const storedKey = `useStoredReducer.${GAME}.${key}`; const getInitialValue = (): T => { try { diff --git a/src/games/hordeseer/contexts/state.tsx b/src/games/hordeseer/contexts/state.tsx index 1a8e373..e230a00 100644 --- a/src/games/hordeseer/contexts/state.tsx +++ b/src/games/hordeseer/contexts/state.tsx @@ -63,7 +63,7 @@ export const useHordeState = () => useContext(HordeContext); const POLL_INTERVAL_MS = 30_000; export const HordeStateProvider = ({ children }: { children: preact.ComponentChildren }) => { - const [state, dispatch] = useStoredReducer('horde.state', reducer, DEFAULT_STATE); + const [state, dispatch] = useStoredReducer('state', reducer, DEFAULT_STATE); const leaderboard = useBool(false); const options = useBool(false); diff --git a/src/games/storywriter/contexts/state.tsx b/src/games/storywriter/contexts/state.tsx index fc554a1..708287d 100644 --- a/src/games/storywriter/contexts/state.tsx +++ b/src/games/storywriter/contexts/state.tsx @@ -696,7 +696,7 @@ export const useAppState = () => useContext(StateContext); // ─── Provider ──────────────────────────────────────────────────────────────── export const StateContextProvider = ({ children }: { children?: any }) => { - const [state, dispatch] = useStoredReducer('storywriter.state', reducer, DEFAULT_STATE); + const [state, dispatch] = useStoredReducer('state', reducer, DEFAULT_STATE); const value = useMemo(() => { const currentWorld = state.worlds.find(w => w.id === state.currentWorldId) ?? null;