From 49782c0b730cce9f0bad14e9c83842b5b0bfe11e Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Sun, 28 Mar 2021 22:02:03 -0400 Subject: [PATCH] fix(frontend): 'Recent Requests' slider should link to request list w/ same filter (#1235) * fix(frontend): 'Recent Requests' slider should link to request list w/ same filter * fix(frontend): use 'all' instead of 'unavailable' filter for recent requests slider * refactor: use enum for request list filter --- src/components/Discover/index.tsx | 4 ++-- src/components/RequestList/index.tsx | 26 +++++++++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/components/Discover/index.tsx b/src/components/Discover/index.tsx index 74e416f6a..9a4d05c8e 100644 --- a/src/components/Discover/index.tsx +++ b/src/components/Discover/index.tsx @@ -38,7 +38,7 @@ const Discover: React.FC = () => { data: requests, error: requestError, } = useSWR( - '/api/v1/request?filter=unavailable&take=10&sort=modified&skip=0', + '/api/v1/request?filter=all&take=10&sort=modified&skip=0', { revalidateOnMount: true } ); @@ -63,7 +63,7 @@ const Discover: React.FC = () => { ))} />
- + {intl.formatMessage(messages.recentrequests)} { const router = useRouter(); const intl = useIntl(); - const [currentFilter, setCurrentFilter] = useState('pending'); + const [currentFilter, setCurrentFilter] = useState(Filter.PENDING); const [currentSort, setCurrentSort] = useState('added'); const [currentPageSize, setCurrentPageSize] = useState(10); @@ -47,7 +55,12 @@ const RequestList: React.FC = () => { setCurrentSort(filterSettings.currentSort); setCurrentPageSize(filterSettings.currentPageSize); } - }, []); + + // If filter value is provided in query, use that instead + if (Object.values(Filter).includes(router.query.filter as Filter)) { + setCurrentFilter(router.query.filter as Filter); + } + }, [router.query.filter]); // Set filter values to local storage any time they are changed useEffect(() => { @@ -118,6 +131,9 @@ const RequestList: React.FC = () => { +
@@ -167,11 +183,11 @@ const RequestList: React.FC = () => { {intl.formatMessage(globalMessages.noresults)} - {currentFilter !== 'all' && ( + {currentFilter !== Filter.ALL && (