umami/store/app.js

36 lines
762 B
JavaScript
Raw Normal View History

import create from 'zustand';
2022-08-04 12:56:30 +02:00
import { DEFAULT_LOCALE, DEFAULT_THEME, LOCALE_CONFIG, THEME_CONFIG } from 'lib/constants';
2022-08-29 05:20:54 +02:00
import { getItem } from 'next-basics';
const initialState = {
locale: getItem(LOCALE_CONFIG) || DEFAULT_LOCALE,
theme: getItem(THEME_CONFIG) || DEFAULT_THEME,
shareToken: null,
user: null,
config: 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 });
}
export function setConfig(config) {
store.setState({ config });
}
export default store;