(test) use fuzzysort
This commit is contained in:
parent
a37847fe70
commit
314fa28773
3 changed files with 22 additions and 1 deletions
|
|
@ -33,6 +33,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@swc/helpers": "0.5.0",
|
||||
"fuzzysort": "^2.0.4",
|
||||
"spitroast": "^1.4.3"
|
||||
},
|
||||
"pnpm": {
|
||||
|
|
|
|||
7
pnpm-lock.yaml
generated
7
pnpm-lock.yaml
generated
|
|
@ -8,6 +8,9 @@ dependencies:
|
|||
'@swc/helpers':
|
||||
specifier: 0.5.0
|
||||
version: 0.5.0
|
||||
fuzzysort:
|
||||
specifier: ^2.0.4
|
||||
version: 2.0.4
|
||||
spitroast:
|
||||
specifier: ^1.4.3
|
||||
version: 1.4.3
|
||||
|
|
@ -488,6 +491,10 @@ packages:
|
|||
'@esbuild/win32-x64': 0.17.19
|
||||
dev: true
|
||||
|
||||
/fuzzysort@2.0.4:
|
||||
resolution: {integrity: sha512-Api1mJL+Ad7W7vnDZnWq5pGaXJjyencT+iKGia2PlHUcSsSzWwIQ3S1isiMpwpavjYtGd2FzhUIhnnhOULZgDw==}
|
||||
dev: false
|
||||
|
||||
/invariant@2.2.4:
|
||||
resolution: {integrity: sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==}
|
||||
dependencies:
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { HTTP_REGEX_MULTI } from "@/lib/utils/constants";
|
|||
import { showInputAlert } from "@ui/alerts";
|
||||
import { getAssetIDByName } from "@/lib/api/assets";
|
||||
import { Strings, formatString } from "@/core/i18n";
|
||||
import fuzzysort from "fuzzysort";
|
||||
|
||||
interface AddonPageProps<T> {
|
||||
title: string;
|
||||
|
|
@ -18,6 +19,18 @@ interface AddonPageProps<T> {
|
|||
card: React.ComponentType<CardWrapper<T>>;
|
||||
}
|
||||
|
||||
function getItemsByQuery<T extends { id?: string }>(items: T[], query: string): T[] {
|
||||
if (!query) return items;
|
||||
|
||||
return fuzzysort.go(query, items, { keys: [
|
||||
"id",
|
||||
"manifest.name",
|
||||
"manifest.description",
|
||||
"manifest.authors.0.name",
|
||||
"manifest.authors.1.name"
|
||||
]}).map(r => r.obj);
|
||||
}
|
||||
|
||||
const reanimated = findByProps("useSharedValue");
|
||||
const { FloatingActionButton } = findByProps("FloatingActionButton");
|
||||
|
||||
|
|
@ -52,7 +65,7 @@ export default function AddonPage<T>({ title, fetchFunction, items, safeModeMess
|
|||
onMomentumScrollEnd={() => collapseText.value = 0}
|
||||
style={{ paddingHorizontal: 10, paddingTop: 10 }}
|
||||
contentContainerStyle={{ paddingBottom: 70 }}
|
||||
data={Object.values(items).filter(i => i.id?.toLowerCase().includes(search))}
|
||||
data={getItemsByQuery(Object.values(items), search)}
|
||||
renderItem={({ item, index }) => <CardComponent item={item} index={index} />}
|
||||
/>
|
||||
<FloatingActionButton
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue