From 45e3484b008ec25e421033d4e5d2707667169d31 Mon Sep 17 00:00:00 2001 From: Mateusz Titz Date: Thu, 18 Jul 2024 15:22:21 +0200 Subject: [PATCH] Refactor advanced filters definition --- src/pages/Search/AdvancedSearchFilters.tsx | 34 ++++++++++++---------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/pages/Search/AdvancedSearchFilters.tsx b/src/pages/Search/AdvancedSearchFilters.tsx index 7b6bb64cc6b5..171e2c45dbd7 100644 --- a/src/pages/Search/AdvancedSearchFilters.tsx +++ b/src/pages/Search/AdvancedSearchFilters.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, {useMemo} from 'react'; import {View} from 'react-native'; import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import useLocalize from '@hooks/useLocalize'; @@ -7,19 +7,6 @@ import useWaitForNavigation from '@hooks/useWaitForNavigation'; import Navigation from '@libs/Navigation/Navigation'; import ROUTES from '@src/ROUTES'; -const advancedFilters = [ - { - fieldName: 'type', - description: 'common.type' as const, - route: ROUTES.SEARCH_ADVANCED_FILTERS_TYPE, - }, - { - fieldName: 'date', - description: 'common.date' as const, - route: ROUTES.SEARCH_ADVANCED_FILTERS_DATE, - }, -]; - function getFilterDisplayTitle(filters: Record, fieldName: string) { // This is temporary because the full parsing of search query is not yet done // TODO once we have values from query, this value should be `filters[fieldName].value` @@ -31,16 +18,31 @@ function AdvancedSearchFilters() { const {singleExecution} = useSingleExecution(); const waitForNavigate = useWaitForNavigation(); + const advancedFilters = useMemo( + () => [ + { + title: getFilterDisplayTitle({}, 'title'), + description: 'common.type' as const, + route: ROUTES.SEARCH_ADVANCED_FILTERS_TYPE, + }, + { + title: getFilterDisplayTitle({}, 'date'), + description: 'common.date' as const, + route: ROUTES.SEARCH_ADVANCED_FILTERS_DATE, + }, + ], + [], + ); + return ( {advancedFilters.map((item) => { - const filterValue = getFilterDisplayTitle({}, item.fieldName); const onPress = singleExecution(waitForNavigate(() => Navigation.navigate(item.route))); return (