1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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;
|