From 84ec58873a36b662f02df97f2a979c51d76ad1ea Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Fri, 3 May 2024 17:27:48 -0700 Subject: [PATCH] fix: tag delete issue --- src/lib/components/chat/Tags.svelte | 19 ++++++++++++++++--- .../components/layout/Sidebar/ChatMenu.svelte | 8 +++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/lib/components/chat/Tags.svelte b/src/lib/components/chat/Tags.svelte index 277a47801..47e63198f 100644 --- a/src/lib/components/chat/Tags.svelte +++ b/src/lib/components/chat/Tags.svelte @@ -4,11 +4,14 @@ deleteTagById, getAllChatTags, getChatList, + getChatListByTagName, getTagsById, updateChatById } from '$lib/apis/chats'; import { tags as _tags, chats } from '$lib/stores'; - import { onMount } from 'svelte'; + import { createEventDispatcher, onMount } from 'svelte'; + + const dispatch = createEventDispatcher(); import Tags from '../common/Tags.svelte'; @@ -40,9 +43,19 @@ tags: tags }); - _tags.set(await getAllChatTags(localStorage.token)); + console.log($_tags); - if (!$_tags.includes(tagName)) { + await _tags.set(await getAllChatTags(localStorage.token)); + + console.log($_tags); + + if ($_tags.map((t) => t.name).includes(tagName)) { + await chats.set(await getChatListByTagName(localStorage.token, tagName)); + + if ($chats.find((chat) => chat.id === chatId)) { + dispatch('close'); + } + } else { await chats.set(await getChatList(localStorage.token)); } }; diff --git a/src/lib/components/layout/Sidebar/ChatMenu.svelte b/src/lib/components/layout/Sidebar/ChatMenu.svelte index 1cf629c5a..29b8e61cf 100644 --- a/src/lib/components/layout/Sidebar/ChatMenu.svelte +++ b/src/lib/components/layout/Sidebar/ChatMenu.svelte @@ -75,7 +75,13 @@
- + { + show = false; + onClose(); + }} + />