Skip to content

Commit

Permalink
Update search bar with state
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgoth committed Jun 1, 2022
1 parent 16b12cb commit ff86303
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions modules/app/components/filters/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
13 changes: 9 additions & 4 deletions pages/polling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -157,8 +164,6 @@ const PollingOverview = ({ polls, tags }: PollingPageData) => {
mutateAllUserVotes();
}, [addressToCheck]);

const [title, setTitle] = useUiFiltersStore(state => [state.pollFilters.title, state.setTitle], shallow);

return (
<PrimaryLayout sx={{ maxWidth: [null, null, null, 'page', 'dashboard'] }}>
<HeadComponent
Expand Down

0 comments on commit ff86303

Please sign in to comment.