mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-16 02:05:04 +01:00
19 lines
571 B
JavaScript
19 lines
571 B
JavaScript
import { useSelector } from 'react-redux';
|
|
import { parseISO } from 'date-fns';
|
|
import { getDateRange } from 'lib/date';
|
|
import { getItem } from 'lib/web';
|
|
|
|
export function useDateRange(websiteId, defaultDateRange = '7day') {
|
|
const globalDefault = getItem('umami.date-range');
|
|
|
|
if (globalDefault) {
|
|
globalDefault.startDate = parseISO(globalDefault.startDate);
|
|
globalDefault.endDate = parseISO(globalDefault.endDate);
|
|
}
|
|
|
|
return useSelector(
|
|
state =>
|
|
state.websites[websiteId]?.dateRange || globalDefault || getDateRange(defaultDateRange),
|
|
);
|
|
}
|