From ff863030cdb3351b548be238e703f0af254c5a2e Mon Sep 17 00:00:00 2001 From: Adam Goth Date: Wed, 1 Jun 2022 12:17:45 +0200 Subject: [PATCH] Update search bar with state --- modules/app/components/filters/SearchBar.tsx | 6 ++++++ pages/polling.tsx | 13 +++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/app/components/filters/SearchBar.tsx b/modules/app/components/filters/SearchBar.tsx index b8ca90e20..38691631a 100644 --- a/modules/app/components/filters/SearchBar.tsx +++ b/modules/app/components/filters/SearchBar.tsx @@ -13,6 +13,12 @@ type Props = { export const SearchBar = ({ onChange, value, placeholder = 'Search', ...props }: Props): JSX.Element => { const [searchTerm, setSearchTerm] = useState(''); + useEffect(() => { + if (value) { + setSearchTerm(value); + } + }, []); + const handleInput = event => { setSearchTerm(event.target.value); debounce(onChange(event.target.value)); diff --git a/pages/polling.tsx b/pages/polling.tsx index 886a37267..356aba6ae 100644 --- a/pages/polling.tsx +++ b/pages/polling.tsx @@ -76,8 +76,15 @@ const getSortCriteria = (sort: PollsSortEnum | null) => { const PollingOverview = ({ polls, tags }: PollingPageData) => { const { trackButtonClick } = useAnalytics(ANALYTICS_PAGES.POLLING); - const [pollFilters, setCategoryFilter, resetPollFilters, sort] = useUiFiltersStore( - state => [state.pollFilters, state.setCategoryFilter, state.resetPollFilters, state.pollsSortBy], + const [pollFilters, setCategoryFilter, resetPollFilters, sort, title, setTitle] = useUiFiltersStore( + state => [ + state.pollFilters, + state.setCategoryFilter, + state.resetPollFilters, + state.pollsSortBy, + state.pollFilters.title, + state.setTitle + ], shallow ); const setFilteredPolls = usePollsStore(state => state.setFilteredPolls); @@ -157,8 +164,6 @@ const PollingOverview = ({ polls, tags }: PollingPageData) => { mutateAllUserVotes(); }, [addressToCheck]); - const [title, setTitle] = useUiFiltersStore(state => [state.pollFilters.title, state.setTitle], shallow); - return (