Skip to content

Commit

Permalink
fix: Search filters fix (#2087)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Bulat authored Apr 18, 2024
1 parent b6c4514 commit adfd8ec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/contexts/Filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,14 @@ export const FiltersProvider = ({ children }: { children: ReactNode }) => {
if (o === 'default') {
newOrders = [...orders].filter((order) => order.key !== g);
} else if (orders.length) {
// Attempt to replace the order record if it exists.
newOrders = [...orders].map((order) =>
order.key !== g ? order : { ...order, order: o }
);
// If order for this key does not exist, add it.
if (newOrders.find(({ key }) => key === g) === undefined) {
newOrders.push({ key: g, order: o });
}
} else {
newOrders = [{ key: g, order: o }];
}
Expand All @@ -151,9 +156,15 @@ export const FiltersProvider = ({ children }: { children: ReactNode }) => {
const setSearchTerm = (g: string, t: string) => {
let newSearchTerms = [];
if (orders.length) {
// Attempt to replace the search term if it exists.
newSearchTerms = [...searchTerms].map((term) =>
term.key !== g ? term : { ...term, searchTerm: t }
);

// If search term for this key does not exist, add it.
if (newSearchTerms.find(({ key }) => key === g) === undefined) {
newSearchTerms.push({ key: g, searchTerm: t });
}
} else {
newSearchTerms = [{ key: g, searchTerm: t }];
}
Expand Down
1 change: 1 addition & 0 deletions src/library/PoolList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const PoolList = ({

const handleSearchChange = (e: FormEvent<HTMLInputElement>) => {
const newValue = e.currentTarget.value;

let filteredPools: BondedPool[] = Object.assign(poolsDefault);
filteredPools = applyFilter(includes, excludes, filteredPools);
filteredPools = poolSearchFilter(filteredPools, newValue);
Expand Down
2 changes: 1 addition & 1 deletion src/library/ValidatorList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ export const ValidatorListInner = ({
index === self.findIndex((i) => i.address === value.address)
);

setValidators(filteredValidators);
setPage(1);
setValidators(filteredValidators);
setIsSearching(e.currentTarget.value !== '');
setSearchTerm('validators', newValue);
};
Expand Down

0 comments on commit adfd8ec

Please sign in to comment.