diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-11-15 17:17:50 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-15 17:17:50 -0800 |
commit | 6616b2bff098ff4a5e464c175edf2446dae0cc88 (patch) | |
tree | fb314b51dd3d17b488fa2971735aa7c19176493b /src/state/shell/tick-every-minute.tsx | |
parent | f23e9978d839322aab7304d2b6f183722e3ad4c1 (diff) | |
download | voidsky-6616b2bff098ff4a5e464c175edf2446dae0cc88.tar.zst |
Shell behaviors update (react-query refactor) (#1915)
* Move tick-every-minute into a hook/context * Move soft-reset event out of the shell model * Update soft-reset listener on new search page * Implement session-loaded and session-dropped events * Update analytics and push-notifications to use new session system
Diffstat (limited to 'src/state/shell/tick-every-minute.tsx')
-rw-r--r-- | src/state/shell/tick-every-minute.tsx | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/state/shell/tick-every-minute.tsx b/src/state/shell/tick-every-minute.tsx new file mode 100644 index 000000000..c37221c90 --- /dev/null +++ b/src/state/shell/tick-every-minute.tsx @@ -0,0 +1,20 @@ +import React from 'react' + +type StateContext = number + +const stateContext = React.createContext<StateContext>(0) + +export function Provider({children}: React.PropsWithChildren<{}>) { + const [tick, setTick] = React.useState(Date.now()) + React.useEffect(() => { + const i = setInterval(() => { + setTick(Date.now()) + }, 60_000) + return () => clearInterval(i) + }, []) + return <stateContext.Provider value={tick}>{children}</stateContext.Provider> +} + +export function useTickEveryMinute() { + return React.useContext(stateContext) +} |