Просмотр исходного кода

refac: chat tag suggestions behaviour

Timothy Jaeryang Baek 3 месяцев назад
Родитель
Сommit
38f45a38cb

+ 2 - 1
src/lib/components/chat/Messages/RateComment.svelte

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

+ 1 - 0
src/lib/components/chat/Tags.svelte

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

+ 2 - 0
src/lib/components/common/Tags.svelte

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

+ 9 - 5
src/lib/components/common/Tags/TagInput.svelte

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