mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
25 lines
758 B
JavaScript
25 lines
758 B
JavaScript
import { useSelector } from 'react-redux';
|
|
import { parseISO } from 'date-fns';
|
|
import { getDateRange } from 'lib/date';
|
|
import { getItem } from 'lib/web';
|
|
|
|
export default function useDateRange(websiteId, defaultDateRange = '24hour') {
|
|
const globalDefault = getItem('umami.date-range');
|
|
let globalDateRange;
|
|
|
|
if (typeof globalDefault === 'string') {
|
|
globalDateRange = getDateRange(globalDefault);
|
|
} else if (typeof globalDateRange === 'object') {
|
|
globalDateRange = {
|
|
...globalDefault,
|
|
startDate: parseISO(globalDefault.startDate),
|
|
endDate: parseISO(globalDefault.endDate),
|
|
};
|
|
}
|
|
|
|
return useSelector(
|
|
state =>
|
|
state.websites[websiteId]?.dateRange || globalDateRange || getDateRange(defaultDateRange),
|
|
);
|
|
}
|