2022-02-23 07:47:59 +01:00
|
|
|
import create from 'zustand';
|
2023-03-09 01:37:43 +01:00
|
|
|
import {
|
|
|
|
DATE_RANGE_CONFIG,
|
|
|
|
DEFAULT_DATE_RANGE,
|
|
|
|
DEFAULT_LOCALE,
|
|
|
|
DEFAULT_THEME,
|
|
|
|
LOCALE_CONFIG,
|
|
|
|
THEME_CONFIG,
|
|
|
|
} from 'lib/constants';
|
2022-08-29 05:20:54 +02:00
|
|
|
import { getItem } from 'next-basics';
|
2022-03-02 08:03:50 +01:00
|
|
|
|
2022-02-23 07:47:59 +01:00
|
|
|
const initialState = {
|
|
|
|
locale: getItem(LOCALE_CONFIG) || DEFAULT_LOCALE,
|
|
|
|
theme: getItem(THEME_CONFIG) || DEFAULT_THEME,
|
2023-03-09 01:37:43 +01:00
|
|
|
dateRange: getItem(DATE_RANGE_CONFIG) || DEFAULT_DATE_RANGE,
|
2022-02-23 07:47:59 +01:00
|
|
|
shareToken: null,
|
|
|
|
user: null,
|
2022-08-02 08:04:47 +02:00
|
|
|
config: null,
|
2022-02-23 07:47:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const store = create(() => ({ ...initialState }));
|
|
|
|
|
|
|
|
export function setTheme(theme) {
|
|
|
|
store.setState({ theme });
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setLocale(locale) {
|
|
|
|
store.setState({ locale });
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setShareToken(shareToken) {
|
|
|
|
store.setState({ shareToken });
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setUser(user) {
|
|
|
|
store.setState({ user });
|
|
|
|
}
|
|
|
|
|
2022-08-02 08:04:47 +02:00
|
|
|
export function setConfig(config) {
|
|
|
|
store.setState({ config });
|
|
|
|
}
|
|
|
|
|
2023-03-09 01:37:43 +01:00
|
|
|
export function setDateRange(dateRange) {
|
|
|
|
store.setState({ dateRange });
|
|
|
|
}
|
|
|
|
|
2022-02-23 07:47:59 +01:00
|
|
|
export default store;
|