#36 initialize search

This commit is contained in:
neil 2022-12-21 15:21:38 +08:00
parent 74ffe61951
commit a3be80627c
2 changed files with 22 additions and 1 deletions

View file

@ -2,6 +2,7 @@
import { page } from '$app/stores';
import { open } from '@tauri-apps/api/shell';
import { appWindow } from '@tauri-apps/api/window';
import { searchStore } from '$libs/stores';
import SearchInput from '@tea/ui/SearchInput/SearchInput.svelte';
import Button from '@tea/ui/Button/Button.svelte';
@ -63,7 +64,7 @@
});
const onSearch = (term: string) => {
console.log('navbar search:', term);
searchStore.search(term);
};
</script>

View file

@ -60,3 +60,23 @@ function initPackagesReviewStore() {
}
export const packagesReviewStore = initPackagesReviewStore();
function initSearchStore() {
const { subscribe, set } = writable<string>('');
// TODO:
// add fuse.js index here: packages, articles/posts, etc
// define fuse.js shape { tags:[], desc:string, title: string, thumb_image_url: string }
// should use algolia if user is somehow online
let term = '';
subscribe((v) => (term = v));
return {
term,
subscribe,
search: (term: string) => set(term)
};
}
export const searchStore = initSearchStore();