refac: chat tag suggestions behaviour

This commit is contained in:
Timothy Jaeryang Baek 2025-11-13 00:06:32 -05:00
parent 84912904fd
commit 38f45a38cb
4 changed files with 14 additions and 6 deletions

View file

@ -2,7 +2,7 @@
import { toast } from 'svelte-sonner'; import { toast } from 'svelte-sonner';
import { createEventDispatcher, onMount, getContext } from 'svelte'; import { createEventDispatcher, onMount, getContext } from 'svelte';
import { config, models } from '$lib/stores'; import { config, models, tags as _tags } from '$lib/stores';
import Tags from '$lib/components/common/Tags.svelte'; import Tags from '$lib/components/common/Tags.svelte';
import XMark from '$lib/components/icons/XMark.svelte'; import XMark from '$lib/components/icons/XMark.svelte';
@ -225,6 +225,7 @@
<div class="flex items-end group"> <div class="flex items-end group">
<Tags <Tags
{tags} {tags}
suggestionTags={$_tags ?? []}
on:delete={(e) => { on:delete={(e) => {
tags = tags.filter( tags = tags.filter(
(tag) => (tag) =>

View file

@ -73,6 +73,7 @@
<Tags <Tags
{tags} {tags}
suggestionTags={$_tags ?? []}
on:delete={(e) => { on:delete={(e) => {
deleteTag(e.detail); deleteTag(e.detail);
}} }}

View file

@ -7,6 +7,7 @@
const i18n = getContext('i18n'); const i18n = getContext('i18n');
export let tags = []; export let tags = [];
export let suggestionTags = [];
</script> </script>
<ul class="flex flex-row flex-wrap gap-[0.3rem] line-clamp-1"> <ul class="flex flex-row flex-wrap gap-[0.3rem] line-clamp-1">
@ -19,6 +20,7 @@
<TagInput <TagInput
label={tags.length == 0 ? $i18n.t('Add Tags') : ''} label={tags.length == 0 ? $i18n.t('Add Tags') : ''}
{suggestionTags}
on:add={(e) => { on:add={(e) => {
dispatch('add', e.detail); dispatch('add', e.detail);
}} }}

View file

@ -7,6 +7,8 @@
const i18n = getContext('i18n'); const i18n = getContext('i18n');
export let label = ''; export let label = '';
export let suggestionTags = [];
let showTagInput = false; let showTagInput = false;
let tagName = ''; let tagName = '';
@ -37,11 +39,13 @@
} }
}} }}
/> />
<datalist id="tagOptions"> {#if suggestionTags.length > 0}
{#each $tags as tag} <datalist id="tagOptions">
<option value={tag.name} /> {#each suggestionTags as tag}
{/each} <option value={tag.name} />
</datalist> {/each}
</datalist>
{/if}
<button type="button" aria-label={$i18n.t('Save Tag')} on:click={addTagHandler}> <button type="button" aria-label={$i18n.t('Save Tag')} on:click={addTagHandler}>
<svg <svg