Fix refresh button issue, closes #840

This commit is contained in:
Mike Cao 2021-12-19 22:49:08 -08:00
parent 7b7557ec90
commit 504b5f10d9
3 changed files with 6 additions and 7 deletions

View File

@ -117,8 +117,6 @@ const DaySelector = ({ date, minDate, maxDate, locale, onSelect }) => {
const month = date.getMonth(); const month = date.getMonth();
const year = date.getFullYear(); const year = date.getFullYear();
console.log({ dateLocale, startDay, startWeek, startMonth, month, year });
const daysOfWeek = []; const daysOfWeek = [];
for (let i = 0; i < 7; i++) { for (let i = 0; i < 7; i++) {
daysOfWeek.push(addDays(startWeek, i)); daysOfWeek.push(addDays(startWeek, i));

View File

@ -7,12 +7,9 @@ import Button from './Button';
import Refresh from 'assets/redo.svg'; import Refresh from 'assets/redo.svg';
import Dots from 'assets/ellipsis-h.svg'; import Dots from 'assets/ellipsis-h.svg';
import useDateRange from 'hooks/useDateRange'; import useDateRange from 'hooks/useDateRange';
import { getDateRange } from '../../lib/date';
import useLocale from 'hooks/useLocale';
function RefreshButton({ websiteId }) { function RefreshButton({ websiteId }) {
const dispatch = useDispatch(); const dispatch = useDispatch();
const { locale } = useLocale();
const [dateRange] = useDateRange(websiteId); const [dateRange] = useDateRange(websiteId);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const completed = useSelector(state => state.queries[`/api/website/${websiteId}/stats`]); const completed = useSelector(state => state.queries[`/api/website/${websiteId}/stats`]);
@ -20,7 +17,7 @@ function RefreshButton({ websiteId }) {
function handleClick() { function handleClick() {
if (dateRange) { if (dateRange) {
setLoading(true); setLoading(true);
dispatch(setDateRange(websiteId, getDateRange(dateRange.value, locale))); dispatch(setDateRange(websiteId, dateRange));
} }
} }

View File

@ -39,7 +39,11 @@ export function getDateRange(value, locale = 'en-US') {
const now = new Date(); const now = new Date();
const dateLocale = getDateLocale(locale); const dateLocale = getDateLocale(locale);
const { num, unit } = value.match(/^(?<num>[0-9]+)(?<unit>hour|day|week|month|year)$/).groups; const match = value.match(/^(?<num>[0-9]+)(?<unit>hour|day|week|month|year)$/);
if (!match) return;
const { num, unit } = match.groups;
if (+num === 1) { if (+num === 1) {
switch (unit) { switch (unit) {