forked from open-webui/open-webui
feat: chat menu tag
This commit is contained in:
parent
3488b7f006
commit
323b9adc63
4 changed files with 67 additions and 1 deletions
52
src/lib/components/chat/Tags.svelte
Normal file
52
src/lib/components/chat/Tags.svelte
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<script>
|
||||||
|
import {
|
||||||
|
addTagById,
|
||||||
|
deleteTagById,
|
||||||
|
getAllChatTags,
|
||||||
|
getTagsById,
|
||||||
|
updateChatById
|
||||||
|
} from '$lib/apis/chats';
|
||||||
|
import { tags as _tags } from '$lib/stores';
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
|
import Tags from '../common/Tags.svelte';
|
||||||
|
|
||||||
|
export let chatId = '';
|
||||||
|
let tags = [];
|
||||||
|
|
||||||
|
const getTags = async () => {
|
||||||
|
return await getTagsById(localStorage.token, chatId).catch(async (error) => {
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const addTag = async (tagName) => {
|
||||||
|
const res = await addTagById(localStorage.token, chatId, tagName);
|
||||||
|
tags = await getTags();
|
||||||
|
|
||||||
|
await updateChatById(localStorage.token, chatId, {
|
||||||
|
tags: tags
|
||||||
|
});
|
||||||
|
|
||||||
|
_tags.set(await getAllChatTags(localStorage.token));
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteTag = async (tagName) => {
|
||||||
|
const res = await deleteTagById(localStorage.token, chatId, tagName);
|
||||||
|
tags = await getTags();
|
||||||
|
|
||||||
|
await updateChatById(localStorage.token, chatId, {
|
||||||
|
tags: tags
|
||||||
|
});
|
||||||
|
|
||||||
|
_tags.set(await getAllChatTags(localStorage.token));
|
||||||
|
};
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
if (chatId) {
|
||||||
|
tags = await getTags();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Tags {tags} {deleteTag} {addTag} />
|
|
@ -4,10 +4,12 @@
|
||||||
|
|
||||||
import { flyAndScale } from '$lib/utils/transitions';
|
import { flyAndScale } from '$lib/utils/transitions';
|
||||||
|
|
||||||
|
export let show = false;
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<DropdownMenu.Root
|
<DropdownMenu.Root
|
||||||
|
bind:open={show}
|
||||||
onOpenChange={(state) => {
|
onOpenChange={(state) => {
|
||||||
dispatch('change', state);
|
dispatch('change', state);
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -538,6 +538,7 @@
|
||||||
{:else}
|
{:else}
|
||||||
<div class="flex self-center space-x-1.5 z-10">
|
<div class="flex self-center space-x-1.5 z-10">
|
||||||
<ChatMenu
|
<ChatMenu
|
||||||
|
chatId={chat.id}
|
||||||
renameHandler={() => {
|
renameHandler={() => {
|
||||||
chatTitle = chat.title;
|
chatTitle = chat.title;
|
||||||
chatTitleEditId = chat.id;
|
chatTitleEditId = chat.id;
|
||||||
|
|
|
@ -6,14 +6,19 @@
|
||||||
import GarbageBin from '$lib/components/icons/GarbageBin.svelte';
|
import GarbageBin from '$lib/components/icons/GarbageBin.svelte';
|
||||||
import Pencil from '$lib/components/icons/Pencil.svelte';
|
import Pencil from '$lib/components/icons/Pencil.svelte';
|
||||||
import Tooltip from '$lib/components/common/Tooltip.svelte';
|
import Tooltip from '$lib/components/common/Tooltip.svelte';
|
||||||
|
import Tags from '$lib/components/chat/Tags.svelte';
|
||||||
|
|
||||||
export let renameHandler: Function;
|
export let renameHandler: Function;
|
||||||
export let deleteHandler: Function;
|
export let deleteHandler: Function;
|
||||||
|
|
||||||
export let onClose: Function;
|
export let onClose: Function;
|
||||||
|
|
||||||
|
export let chatId = '';
|
||||||
|
|
||||||
|
let show = false;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Dropdown
|
<Dropdown
|
||||||
|
bind:show
|
||||||
on:change={(e) => {
|
on:change={(e) => {
|
||||||
if (e.detail === false) {
|
if (e.detail === false) {
|
||||||
onClose();
|
onClose();
|
||||||
|
@ -51,6 +56,12 @@
|
||||||
<GarbageBin strokeWidth="2" />
|
<GarbageBin strokeWidth="2" />
|
||||||
<div class="flex items-center">Delete</div>
|
<div class="flex items-center">Delete</div>
|
||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
|
|
||||||
|
<hr class="border-gray-100 dark:border-gray-800 mt-2.5 mb-1.5" />
|
||||||
|
|
||||||
|
<div class="flex p-1">
|
||||||
|
<Tags {chatId} />
|
||||||
|
</div>
|
||||||
</DropdownMenu.Content>
|
</DropdownMenu.Content>
|
||||||
</div>
|
</div>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
|
|
Loading…
Reference in a new issue