mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-16 02:05:04 +01:00
34 lines
733 B
JavaScript
34 lines
733 B
JavaScript
import { create } from 'zustand';
|
|
import produce from 'immer';
|
|
import app from './app';
|
|
import { parseDateRange } from 'lib/date';
|
|
|
|
const store = create(() => ({}));
|
|
|
|
export function getWebsiteDateRange(websiteId) {
|
|
return store.getState()?.[websiteId];
|
|
}
|
|
|
|
export function setWebsiteDateRange(websiteId, value) {
|
|
store.setState(
|
|
produce(state => {
|
|
if (!state[websiteId]) {
|
|
state[websiteId] = {};
|
|
}
|
|
|
|
let dateRange = value;
|
|
|
|
if (typeof value === 'string') {
|
|
const { locale } = app.getState();
|
|
dateRange = parseDateRange(value, locale);
|
|
}
|
|
|
|
state[websiteId].dateRange = { ...dateRange, modified: Date.now() };
|
|
|
|
return state;
|
|
}),
|
|
);
|
|
}
|
|
|
|
export default store;
|