mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-24 17:11:49 +00:00
feat: use fuzzy search instead
This commit is contained in:
parent
1aa2001860
commit
16c5dfe8be
3 changed files with 18 additions and 8 deletions
|
|
@ -37,6 +37,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.2.0",
|
"axios": "^1.2.0",
|
||||||
"filedrop-svelte": "^0.1.2",
|
"filedrop-svelte": "^0.1.2",
|
||||||
|
"fuse.js": "^6.6.2",
|
||||||
"isomorphic-dompurify": "^0.24.0",
|
"isomorphic-dompurify": "^0.24.0",
|
||||||
"svelte-forms-lib": "^2.0.1",
|
"svelte-forms-lib": "^2.0.1",
|
||||||
"swiper": "^8.4.5",
|
"swiper": "^8.4.5",
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ specifiers:
|
||||||
eslint-config-prettier: ^8.5.0
|
eslint-config-prettier: ^8.5.0
|
||||||
eslint-plugin-svelte3: ^4.0.0
|
eslint-plugin-svelte3: ^4.0.0
|
||||||
filedrop-svelte: ^0.1.2
|
filedrop-svelte: ^0.1.2
|
||||||
|
fuse.js: ^6.6.2
|
||||||
isomorphic-dompurify: ^0.24.0
|
isomorphic-dompurify: ^0.24.0
|
||||||
prettier: ^2.7.1
|
prettier: ^2.7.1
|
||||||
prettier-plugin-svelte: ^2.8.1
|
prettier-plugin-svelte: ^2.8.1
|
||||||
|
|
@ -30,6 +31,7 @@ specifiers:
|
||||||
dependencies:
|
dependencies:
|
||||||
axios: 1.2.0
|
axios: 1.2.0
|
||||||
filedrop-svelte: 0.1.2
|
filedrop-svelte: 0.1.2
|
||||||
|
fuse.js: 6.6.2
|
||||||
isomorphic-dompurify: 0.24.0
|
isomorphic-dompurify: 0.24.0
|
||||||
svelte-forms-lib: 2.0.1
|
svelte-forms-lib: 2.0.1
|
||||||
swiper: 8.4.5
|
swiper: 8.4.5
|
||||||
|
|
@ -1208,6 +1210,11 @@ packages:
|
||||||
resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==}
|
resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==}
|
||||||
dev: true
|
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:
|
/glob-parent/5.1.2:
|
||||||
resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==}
|
resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==}
|
||||||
engines: {node: '>= 6'}
|
engines: {node: '>= 6'}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import type { PageData } from '../$types';
|
import type { PageData } from '../$types';
|
||||||
import CreateCandidateModal from '$lib/components/admin/CreateCandidateModal.svelte';
|
import CreateCandidateModal from '$lib/components/admin/CreateCandidateModal.svelte';
|
||||||
|
import Fuse from 'fuse.js';
|
||||||
|
|
||||||
let candidates: Array<CandidatePreview> = [{}];
|
let candidates: Array<CandidatePreview> = [{}];
|
||||||
|
|
||||||
|
|
@ -57,15 +58,16 @@
|
||||||
|
|
||||||
$: candidatesTable = candidates;
|
$: candidatesTable = candidates;
|
||||||
let searchValue: string = '';
|
let searchValue: string = '';
|
||||||
|
$: fuse = new Fuse(candidates, {
|
||||||
|
keys: ['applicationId', 'name', 'surname', 'study']
|
||||||
|
});
|
||||||
|
|
||||||
const search = () => {
|
const search = () => {
|
||||||
candidatesTable = candidates.filter((candidate) => {
|
if (searchValue === '' || !searchValue) {
|
||||||
return (
|
candidatesTable = candidates;
|
||||||
candidate.applicationId?.toString().toLowerCase().includes(searchValue.toLowerCase()) ||
|
} else {
|
||||||
candidate.name?.toLowerCase().includes(searchValue.toLowerCase()) ||
|
candidatesTable = fuse.search(searchValue).map((result) => result.item);
|
||||||
candidate.surname?.toLowerCase().includes(searchValue.toLowerCase()) ||
|
}
|
||||||
candidate.study?.toLowerCase().includes(searchValue.toLowerCase())
|
|
||||||
);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue