umami/store/websites.js

34 lines
733 B
JavaScript
Raw Normal View History

2023-05-20 18:02:08 +02:00
import { create } from 'zustand';
import produce from 'immer';
2022-03-02 06:13:15 +01:00
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] = {};
}
2022-03-02 06:13:15 +01:00
let dateRange = value;
if (typeof value === 'string') {
const { locale } = app.getState();
dateRange = parseDateRange(value, locale);
2022-03-02 06:13:15 +01:00
}
state[websiteId].dateRange = { ...dateRange, modified: Date.now() };
return state;
}),
);
}
export default store;