feat: archive chat

This commit is contained in:
Timothy J. Baek 2024-04-20 17:03:39 -05:00
parent 00b01c973e
commit fbd520bf07
5 changed files with 125 additions and 3 deletions

View file

@ -282,6 +282,38 @@ export const shareChatById = async (token: string, id: string) => {
return res;
};
export const archiveChatById = async (token: string, id: string) => {
let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/${id}/archive`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
...(token && { authorization: `Bearer ${token}` })
}
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.then((json) => {
return json;
})
.catch((err) => {
error = err;
console.log(err);
return null;
});
if (error) {
throw error;
}
return res;
};
export const deleteSharedChatById = async (token: string, id: string) => {
let error = null;

View file

@ -17,7 +17,8 @@
getChatById,
getChatListByTagName,
updateChatById,
getAllChatTags
getAllChatTags,
archiveChatById
} from '$lib/apis/chats';
import { toast } from 'svelte-sonner';
import { fade, slide } from 'svelte/transition';
@ -139,6 +140,11 @@
localStorage.setItem('settings', JSON.stringify($settings));
location.href = '/';
};
const archiveChatHandler = async (id) => {
await archiveChatById(localStorage.token, id);
await chats.set(await getChatList(localStorage.token));
};
</script>
<ShareChatModal bind:show={showShareChatModal} chatId={shareChatId} />
@ -594,7 +600,7 @@
aria-label="Archive"
class=" self-center dark:hover:text-white transition"
on:click={() => {
selectedChatId = chat.id;
archiveChatHandler(chat.id);
}}
>
<ArchiveBox />