Skip to content

Commit

Permalink
fix: Hoist selected dropdown values to top lazily
Browse files Browse the repository at this point in the history
  • Loading branch information
colin969 committed Aug 1, 2024
1 parent acb8882 commit 1733ddc
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/renderer/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ export function SearchBar() {
value: event.orderReverse
}));
}}/>
<SimpleButton
style={{ height: '100%' }}
value={expanded ? 'Hide Filters' : 'Show Filters'}
onClick={() => setExpanded(!expanded)}/>
{/* <SimpleButton */}
{/* style={{ height: '100%' }} */}
{/* value={expanded ? 'Hide Filters' : 'Show Filters'} */}
{/* onClick={() => setExpanded(!expanded)}/> */}
</div>
{ expanded &&
(
Expand Down Expand Up @@ -362,9 +362,15 @@ function SearchableSelectDropdown<T extends SearchableSelectItem>(props: Searcha
const [search, setSearch] = React.useState('');
const [storedItems, setStoredItems] = React.useState(items); // 'cache' the items

// Split the items into 2 halves - Selected and not selected, then merge

const filteredItems = React.useMemo(() => {
const lowerSearch = search.toLowerCase().replace(' ', '');
return storedItems.filter((item) => item.orderVal.toLowerCase().replace(' ', '').includes(lowerSearch));

return [
...storedItems.filter((item) => selected.includes(item.value) && item.orderVal.toLowerCase().includes(lowerSearch)),
...storedItems.filter((item) => !selected.includes(item.value) && item.orderVal.toLowerCase().includes(lowerSearch)),
];
}, [search, storedItems]);

// Update the stored items when all selections removed
Expand Down

0 comments on commit 1733ddc

Please sign in to comment.