2022-02-23 07:47:59 +01:00
|
|
|
import create from 'zustand';
|
2022-03-02 08:03:50 +01:00
|
|
|
import {
|
|
|
|
DASHBOARD_CONFIG,
|
|
|
|
DEFAULT_LOCALE,
|
|
|
|
DEFAULT_THEME,
|
|
|
|
LOCALE_CONFIG,
|
|
|
|
THEME_CONFIG,
|
|
|
|
DEFAULT_WEBSITE_LIMIT,
|
|
|
|
} from 'lib/constants';
|
2022-04-04 18:15:49 +02:00
|
|
|
import { getItem, setItem } from 'lib/web';
|
2022-02-23 07:47:59 +01:00
|
|
|
|
2022-03-04 04:45:49 +01:00
|
|
|
export const defaultDashboardConfig = {
|
2022-03-02 08:03:50 +01:00
|
|
|
showCharts: true,
|
|
|
|
limit: DEFAULT_WEBSITE_LIMIT,
|
2022-07-24 08:01:59 +02:00
|
|
|
websiteOrdering: {},
|
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,
|
2022-03-02 08:03:50 +01:00
|
|
|
dashboard: getItem(DASHBOARD_CONFIG) || defaultDashboardConfig,
|
2022-02-23 07:47:59 +01:00
|
|
|
shareToken: null,
|
|
|
|
user: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
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-03-02 08:03:50 +01:00
|
|
|
export function setDashboard(dashboard) {
|
|
|
|
store.setState({ dashboard });
|
2022-04-04 18:15:49 +02:00
|
|
|
setItem(DASHBOARD_CONFIG, dashboard);
|
2022-03-02 08:03:50 +01:00
|
|
|
}
|
|
|
|
|
2022-02-23 07:47:59 +01:00
|
|
|
export default store;
|