From 9f9f113a0e955b00f34ddfb986c7517e69a95145 Mon Sep 17 00:00:00 2001 From: developomp Date: Mon, 9 Aug 2021 22:55:36 +0900 Subject: [PATCH] fixed date range not updating on clear button pressed --- source/src/pages/Search.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/source/src/pages/Search.tsx b/source/src/pages/Search.tsx index 4f4475d..2c69848 100644 --- a/source/src/pages/Search.tsx +++ b/source/src/pages/Search.tsx @@ -104,13 +104,21 @@ function _Search() { query: _query.query ? _query.query.toString() : "", } - const [dateRange, setDateRange] = useState([ + const defaultDateRange = [ { - startDate: new Date(0), // default date + startDate: new Date(0), endDate: null, key: "selection", }, - ]) + ] + + const [dateRange, setDateRange] = useState< + Array<{ + startDate: Date | null + endDate: Date | null + key?: string + }> + >(defaultDateRange) const [postCards, setPostCards] = useState([]) @@ -133,6 +141,9 @@ function _Search() { ranges={dateRange} onChange={(item) => { const historyToPush = { + ...(query.query && { + query: query.query, + }), ...(query.from && { from: query.from, }), @@ -297,6 +308,8 @@ function _Search() { }), }), }) + + setDateRange(defaultDateRange) }} > clear date