mirror of
https://github.com/umami-software/umami.git
synced 2026-02-05 21:27:20 +01:00
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
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;
|