From a3be80627c3392d73eec0913f1c3dca20b14c5ab Mon Sep 17 00:00:00 2001 From: neil Date: Wed, 21 Dec 2022 15:21:38 +0800 Subject: [PATCH] #36 initialize search --- .../gui/src/components/NavBar/NavBar.svelte | 3 ++- modules/gui/src/libs/stores.ts | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/modules/gui/src/components/NavBar/NavBar.svelte b/modules/gui/src/components/NavBar/NavBar.svelte index 7a3d3ed..d50a78b 100644 --- a/modules/gui/src/components/NavBar/NavBar.svelte +++ b/modules/gui/src/components/NavBar/NavBar.svelte @@ -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); }; diff --git a/modules/gui/src/libs/stores.ts b/modules/gui/src/libs/stores.ts index 60dbe7b..c267b52 100644 --- a/modules/gui/src/libs/stores.ts +++ b/modules/gui/src/libs/stores.ts @@ -60,3 +60,23 @@ function initPackagesReviewStore() { } export const packagesReviewStore = initPackagesReviewStore(); + +function initSearchStore() { + const { subscribe, set } = writable(''); + // 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();