feat: use fuzzy search instead

This commit is contained in:
EETagent 2022-12-05 01:26:49 +01:00
parent 1aa2001860
commit 16c5dfe8be
3 changed files with 18 additions and 8 deletions

View file

@ -37,6 +37,7 @@
"dependencies": {
"axios": "^1.2.0",
"filedrop-svelte": "^0.1.2",
"fuse.js": "^6.6.2",
"isomorphic-dompurify": "^0.24.0",
"svelte-forms-lib": "^2.0.1",
"swiper": "^8.4.5",

View file

@ -11,6 +11,7 @@ specifiers:
eslint-config-prettier: ^8.5.0
eslint-plugin-svelte3: ^4.0.0
filedrop-svelte: ^0.1.2
fuse.js: ^6.6.2
isomorphic-dompurify: ^0.24.0
prettier: ^2.7.1
prettier-plugin-svelte: ^2.8.1
@ -30,6 +31,7 @@ specifiers:
dependencies:
axios: 1.2.0
filedrop-svelte: 0.1.2
fuse.js: 6.6.2
isomorphic-dompurify: 0.24.0
svelte-forms-lib: 2.0.1
swiper: 8.4.5
@ -1208,6 +1210,11 @@ packages:
resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==}
dev: true
/fuse.js/6.6.2:
resolution: {integrity: sha512-cJaJkxCCxC8qIIcPBF9yGxY0W/tVZS3uEISDxhYIdtk8OL93pe+6Zj7LjCqVV4dzbqcriOZ+kQ/NE4RXZHsIGA==}
engines: {node: '>=10'}
dev: false
/glob-parent/5.1.2:
resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==}
engines: {node: '>= 6'}

View file

@ -6,6 +6,7 @@
import { onMount } from 'svelte';
import type { PageData } from '../$types';
import CreateCandidateModal from '$lib/components/admin/CreateCandidateModal.svelte';
import Fuse from 'fuse.js';
let candidates: Array<CandidatePreview> = [{}];
@ -57,15 +58,16 @@
$: candidatesTable = candidates;
let searchValue: string = '';
$: fuse = new Fuse(candidates, {
keys: ['applicationId', 'name', 'surname', 'study']
});
const search = () => {
candidatesTable = candidates.filter((candidate) => {
return (
candidate.applicationId?.toString().toLowerCase().includes(searchValue.toLowerCase()) ||
candidate.name?.toLowerCase().includes(searchValue.toLowerCase()) ||
candidate.surname?.toLowerCase().includes(searchValue.toLowerCase()) ||
candidate.study?.toLowerCase().includes(searchValue.toLowerCase())
);
});
if (searchValue === '' || !searchValue) {
candidatesTable = candidates;
} else {
candidatesTable = fuse.search(searchValue).map((result) => result.item);
}
};
</script>