From b17e5590ab6a88f600baf1a079a32ef09eda0c3d Mon Sep 17 00:00:00 2001 From: liyunze <50455574+liyunze-coding@users.noreply.github.com> Date: Thu, 3 Sep 2026 21:07:55 +0800 Subject: [PATCH] added search bar for searching units --- src/lib/components/SearchSelect.svelte | 170 +++++++++++++++++++++++++ src/routes/post/note/+page.svelte | 43 +++++-- src/routes/post/question/+page.svelte | 43 +++++-- 3 files changed, 228 insertions(+), 28 deletions(-) create mode 100644 src/lib/components/SearchSelect.svelte diff --git a/src/lib/components/SearchSelect.svelte b/src/lib/components/SearchSelect.svelte new file mode 100644 index 0000000..e6e7b37 --- /dev/null +++ b/src/lib/components/SearchSelect.svelte @@ -0,0 +1,170 @@ + + +
+ + + {#if open} + +
+
+ (highlight = 0)} + /> +
+
+ + {#each filtered as option, index (option.value)} + + {/each} + {#if filtered.length === 0} +

{emptyMessage}

+ {/if} +
+
+ {/if} +
diff --git a/src/routes/post/note/+page.svelte b/src/routes/post/note/+page.svelte index fd7dd77..dc5b152 100644 --- a/src/routes/post/note/+page.svelte +++ b/src/routes/post/note/+page.svelte @@ -5,6 +5,7 @@ import { onMount } from "svelte"; import { get } from "svelte/store"; import MarkdownEditor from "$lib/components/MarkdownEditor.svelte"; + import SearchSelect from "$lib/components/SearchSelect.svelte"; import { postPath } from "$lib/paths"; import type { TopicDoc, UnitDoc } from "$lib/types"; @@ -19,6 +20,20 @@ let error = $state(""); let loading = $state(false); + const topicOptions = $derived( + topics.map((topic) => ({ + value: topic._id, + label: topic.name, + })), + ); + const unitOptions = $derived( + units.map((unit) => ({ + value: unit._id, + label: `${unit.code}${unit.code2 ? ` / ${unit.code2}` : ""} — ${unit.name}`, + searchText: `${unit.code} ${unit.code2 ?? ""} ${unit.name}`, + })), + ); + onMount(async () => { await initAuth(); if (!get(isAuthenticated)) { @@ -122,25 +137,25 @@
- +
{#if !useCustomUnit} - + {/if}