Skip to content

Commit

Permalink
fix: sort items in fuse (#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
enpitsuLin committed May 28, 2024
1 parent 3edae3f commit 8d052be
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/devtools/client/components/ModuleInstallList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,25 @@ const sortingFactors: Record<typeof sortingOptions[number], SortingFunction<Modu
updated: (a, b) => a.stats.publishedAt - b.stats.publishedAt,
}
const sortedItems = computed(() => collection.value?.slice()
.sort((a, b) => sortingFactors[selectedSortingOption.value](a, b) * (ascendingOrder.value ? 1 : -1)))
const sortedItems = computed(() => collection.value
?.toSorted((a, b) => sortingFactors[selectedSortingOption.value](a, b) * (ascendingOrder.value ? 1 : -1)))
const search = ref('')
const fuse = computed(() => new Fuse(sortedItems.value || [], {
const fuse = computed(() => new Fuse(collection.value || [], {
keys: [
'name',
'description',
'npm',
'category',
],
sortFn: (a, b) => {
const itemA = collection.value?.[a.idx]
const itemB = collection.value?.[b.idx]
if (itemA && itemB)
return sortingFactors[selectedSortingOption.value](itemA, itemB) * (ascendingOrder.value ? 1 : -1)
return (a.score - b.score)
},
threshold: 0.2,
}))
const items = computed(() => {
Expand All @@ -49,7 +57,6 @@ const items = computed(() => {
icon="i-carbon-intent-request-create"
text="Install Module"
/>

<NNavbar v-model:search="search" no-padding px-6 pb-5 pt-2>
<template #actions>
<NDropdown direction="end" n="sm primary">
Expand Down

0 comments on commit 8d052be

Please sign in to comment.