diff --git a/assets/js/dashboard/datepicker.js b/assets/js/dashboard/datepicker.js index 72fd04278..38957dc20 100644 --- a/assets/js/dashboard/datepicker.js +++ b/assets/js/dashboard/datepicker.js @@ -17,24 +17,37 @@ class DatePicker extends React.Component { document.removeEventListener("keyup", this.handleKeyup); } + queryWithPeriod(period, date) { + const query = new URLSearchParams(window.location.search) + query.set('period', period) + + if (date) { + query.set('date', date) + } else { + query.delete('date') + } + + return query.toString() + } + handleKeyup(e) { const {query, history} = this.props if (e.key === 'ArrowLeft') { if (query.period === 'day') { const prevDate = formatISO(shiftDays(query.date, -1)) - history.push('?period=day&date=' + prevDate) + history.push({search: this.queryWithPeriod('day', prevDate)}) } else if (query.period === 'month') { const prevMonth = formatISO(shiftMonths(query.date, -1)) - history.push('?period=month&date=' + prevMonth) + history.push({search: this.queryWithPeriod('month', prevMonth)}) } } else if (e.key === 'ArrowRight') { if (query.period === 'day') { const nextDate = formatISO(shiftDays(query.date, 1)) - history.push('?period=day&date=' + nextDate) + history.push({search: this.queryWithPeriod('day', nextDate)}) } else if (query.period === 'month') { const nextMonth = formatISO(shiftMonths(query.date, 1)) - history.push('?period=month&date=' + nextMonth) + history.push({search: this.queryWithPeriod('month', nextMonth)}) } } } @@ -64,12 +77,12 @@ class DatePicker extends React.Component { renderArrow(period, prevDate, nextDate) { return (