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}