diff options
Diffstat (limited to 'src/store/app.ts')
| -rw-r--r-- | src/store/app.ts | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/store/app.ts b/src/store/app.ts new file mode 100644 index 0000000..bb54e56 --- /dev/null +++ b/src/store/app.ts @@ -0,0 +1,50 @@ +import { create } from 'zustand'; +import { + DATE_RANGE_CONFIG, + DEFAULT_DATE_RANGE_VALUE, + DEFAULT_LOCALE, + DEFAULT_THEME, + LOCALE_CONFIG, + THEME_CONFIG, + TIMEZONE_CONFIG, +} from '@/lib/constants'; +import { getTimezone } from '@/lib/date'; +import { getItem } from '@/lib/storage'; + +const initialState = { + locale: getItem(LOCALE_CONFIG) || process.env.defaultLocale || DEFAULT_LOCALE, + theme: getItem(THEME_CONFIG) || DEFAULT_THEME, + timezone: getItem(TIMEZONE_CONFIG) || getTimezone(), + dateRangeValue: getItem(DATE_RANGE_CONFIG) || DEFAULT_DATE_RANGE_VALUE, + shareToken: null, + user: null, + config: null, +}; + +const store = create(() => ({ ...initialState })); + +export function setTimezone(timezone: string) { + store.setState({ timezone }); +} + +export function setLocale(locale: string) { + store.setState({ locale }); +} + +export function setShareToken(shareToken: string) { + store.setState({ shareToken }); +} + +export function setUser(user: object) { + store.setState({ user }); +} + +export function setConfig(config: object) { + store.setState({ config }); +} + +export function setDateRangeValue(dateRangeValue: string) { + store.setState({ dateRangeValue }); +} + +export const useApp = store; |