fix: search logic

This commit is contained in:
2025-01-25 02:53:16 +01:00
parent 385dcf602c
commit 4631b44d82

View File

@@ -41,17 +41,15 @@
<Command.Root> <Command.Root>
<Command.Input bind:value={search} placeholder="Search topic..." /> <Command.Input bind:value={search} placeholder="Search topic..." />
<Command.List> <Command.List>
<Command.Empty <Command.Empty>
>{#if search && !data.topics.filter((t) => t.name?.includes(search)).length}
<form method="post" action="?/createTopic"> <form method="post" action="?/createTopic">
<input type="hidden" name="name" value={search} /> <input type="hidden" name="name" value={search} />
<button class="px-4 py-2 rounded bg-secondary">Add Topic</button> <button class="px-4 py-2 rounded bg-secondary">Add Topic</button>
</form> </form>
{:else}No topic found. </Command.Empty>
{/if}</Command.Empty
>
<Command.Group> <Command.Group>
{#each data.topics.filter((t) => !search || t.name?.includes(search)) as topic} {#each data.topics as topic}
<form <form
action="?/addTopic" action="?/addTopic"
method="post" method="post"
@@ -60,8 +58,8 @@
> >
<input type="hidden" name="topic-id" value={topic.id} /> <input type="hidden" name="topic-id" value={topic.id} />
<Command.Item <Command.Item
value={topic.id.toString()} value={topic.name!}
onSelect={async () => { onSelect={() => {
addTopicForms[topic.id].submit(); addTopicForms[topic.id].submit();
closeAndFocusTrigger(); closeAndFocusTrigger();
}} }}