fix: tag delete issue

This commit is contained in:
Timothy J. Baek 2024-05-03 17:27:48 -07:00
parent d4db3dd593
commit 84ec58873a
2 changed files with 23 additions and 4 deletions

View File

@ -4,11 +4,14 @@
deleteTagById, deleteTagById,
getAllChatTags, getAllChatTags,
getChatList, getChatList,
getChatListByTagName,
getTagsById, getTagsById,
updateChatById updateChatById
} from '$lib/apis/chats'; } from '$lib/apis/chats';
import { tags as _tags, chats } from '$lib/stores'; 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'; import Tags from '../common/Tags.svelte';
@ -40,9 +43,19 @@
tags: tags 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)); await chats.set(await getChatList(localStorage.token));
} }
}; };

View File

@ -75,7 +75,13 @@
<hr class="border-gray-100 dark:border-gray-800 mt-2.5 mb-1.5" /> <hr class="border-gray-100 dark:border-gray-800 mt-2.5 mb-1.5" />
<div class="flex p-1"> <div class="flex p-1">
<Tags {chatId} /> <Tags
{chatId}
on:close={() => {
show = false;
onClose();
}}
/>
</div> </div>
</DropdownMenu.Content> </DropdownMenu.Content>
</div> </div>