Skip to content

Commit

Permalink
fix: fixing order of filter sections and items
Browse files Browse the repository at this point in the history
  • Loading branch information
Reptarsrage committed Apr 11, 2021
1 parent 64dcb0d commit 7251e86
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/selectors/filterSectionSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,17 @@ export const sectionItemsSelector = createSelector(

if (searchQuery) {
const upper = searchQuery.toUpperCase()
sectionItems = sectionItems.filter((filterId) => filterById[filterId].name.toUpperCase().includes(upper))
sectionItems = sectionItems.map((filterId) => ({
index: filterById[filterId].name.toUpperCase().indexOf(upper),
filterId,
}))

sectionItems = sectionItems.filter((item) => item.index >= 0)
sectionItems.sort((a, b) => {
const diff = a.index - b.index
return diff || filterById[a.filterId].name.localeCompare(filterById[b.filterId].name)
})
sectionItems = sectionItems.map((item) => item.filterId)
} else {
// sort by name
sectionItems.sort((a, b) => filterById[a].name.localeCompare(filterById[b].name))
Expand Down

0 comments on commit 7251e86

Please sign in to comment.