enh: pinned chats support

This commit is contained in:
Timothy J. Baek
2024-07-01 23:08:01 -07:00
parent 439ab7a335
commit 05ec71beb9
9 changed files with 285 additions and 11 deletions

View File

@@ -8,7 +8,7 @@
getTagsById,
updateChatById
} from '$lib/apis/chats';
import { tags as _tags, chats } from '$lib/stores';
import { tags as _tags, chats, pinnedChats } from '$lib/stores';
import { createEventDispatcher, onMount } from 'svelte';
const dispatch = createEventDispatcher();
@@ -19,9 +19,11 @@
let tags = [];
const getTags = async () => {
return await getTagsById(localStorage.token, chatId).catch(async (error) => {
return [];
});
return (
await getTagsById(localStorage.token, chatId).catch(async (error) => {
return [];
})
).filter((tag) => tag.name !== 'pinned');
};
const addTag = async (tagName) => {
@@ -33,6 +35,7 @@
});
_tags.set(await getAllChatTags(localStorage.token));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
};
const deleteTag = async (tagName) => {
@@ -44,19 +47,23 @@
});
console.log($_tags);
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 (tagName === 'pinned') {
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
} else {
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 pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
}
};