mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
26 lines
898 B
JavaScript
26 lines
898 B
JavaScript
import { parseDateRange } from 'lib/date';
|
|
import { setItem } from 'next-basics';
|
|
import { DATE_RANGE_CONFIG, DEFAULT_DATE_RANGE } from 'lib/constants';
|
|
import useLocale from './useLocale';
|
|
import websiteStore, { setWebsiteDateRange } from 'store/websites';
|
|
import appStore, { setDateRange } from 'store/app';
|
|
|
|
export default function useDateRange(websiteId) {
|
|
const { locale } = useLocale();
|
|
const websiteConfig = websiteStore(state => state[websiteId]?.dateRange);
|
|
const defaultConfig = DEFAULT_DATE_RANGE;
|
|
const globalConfig = appStore(state => state.dateRange);
|
|
const dateRange = parseDateRange(websiteConfig || globalConfig || defaultConfig, locale);
|
|
|
|
function saveDateRange(value) {
|
|
if (websiteId) {
|
|
setWebsiteDateRange(websiteId, value);
|
|
} else {
|
|
setItem(DATE_RANGE_CONFIG, value);
|
|
setDateRange(value);
|
|
}
|
|
}
|
|
|
|
return [dateRange, saveDateRange];
|
|
}
|