Skip to content

Commit

Permalink
fix: apply search after loading referenda #1220
Browse files Browse the repository at this point in the history
closes
  • Loading branch information
Nick-1979 committed Oct 22, 2024
1 parent a94a2b1 commit 30fff35
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ export default function SearchBox ({ address, myVotedReferendaIndexes, referenda
const { t } = useTranslation();
const theme = useTheme();
const formatted = useFormatted(address);

const [showAdvanced, setShowAdvanced] = useState<boolean>(false);
const [filter, setFilter] = useState<Filter>(JSON.parse(JSON.stringify(DEFAULT_FILTER)) as Filter);
const [searchKeyword, setSearchKeyword] = useState<string>();

const statusOptions = useMemo(() => REFERENDA_STATUS.map((status, index) => {
return {
Expand Down Expand Up @@ -87,6 +89,8 @@ export default function SearchBox ({ address, myVotedReferendaIndexes, referenda

keyword = keyword.trim();

setSearchKeyword(keyword);

const _filtered = referenda?.filter((r) =>
(filter.advanced.refIndex && String(r.post_id) === keyword) ||
(filter.advanced.titles && r.title && r.title.toLowerCase().includes(keyword.toLowerCase())) ||
Expand Down Expand Up @@ -134,6 +138,13 @@ export default function SearchBox ({ address, myVotedReferendaIndexes, referenda
setFilteredReferenda(isAnyFilterOn ? uniqueFiltered : referenda);
}, [filter, formatted, myVotedReferendaIndexes, referenda, setFilteredReferenda]);

useEffect(() => {
/** To re-apply search keyword on referenda loadings */
if (searchKeyword) {
onSearch(searchKeyword);
}
}, [onSearch, referenda, searchKeyword]);

const onChangeStatus = useCallback((s: number) => {
s = String(s) === 'All' ? 0 : s;
const list = referenda?.filter((ref) => REFERENDA_STATUS[s].includes(ref.status));
Expand All @@ -151,7 +162,7 @@ export default function SearchBox ({ address, myVotedReferendaIndexes, referenda
<InputFilter
autoFocus={false}
onChange={onSearch}
placeholder={t<string>('🔍 Search in all referenda ')}
placeholder={t('🔍 Search in all referenda ')}
theme={theme}
// value={searchKeyword ?? ''}
/>
Expand Down

0 comments on commit 30fff35

Please sign in to comment.