mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat(home stats): load stats progressively
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { create } from 'zustand';
|
||||
|
||||
export type HomepageStatsScope = 'directory' | 'all';
|
||||
|
||||
const LOCALSTORAGE_KEY = '5chan-homepage-stats-scope';
|
||||
|
||||
const readInitialStatsScope = (): HomepageStatsScope => (localStorage.getItem(LOCALSTORAGE_KEY) === 'all' ? 'all' : 'directory');
|
||||
|
||||
interface HomepageStatsOptionsStore {
|
||||
statsScope: HomepageStatsScope;
|
||||
setStatsScope: (value: HomepageStatsScope) => void;
|
||||
}
|
||||
|
||||
const useHomepageStatsOptionsStore = create<HomepageStatsOptionsStore>((set) => ({
|
||||
statsScope: readInitialStatsScope(),
|
||||
setStatsScope: (value) => {
|
||||
set({ statsScope: value });
|
||||
localStorage.setItem(LOCALSTORAGE_KEY, value);
|
||||
},
|
||||
}));
|
||||
|
||||
export default useHomepageStatsOptionsStore;
|
||||
Reference in New Issue
Block a user