|
@@ -1,19 +1,26 @@
|
|
|
-<script>
|
|
|
+<script lang="ts">
|
|
|
import fileSaver from 'file-saver';
|
|
|
const { saveAs } = fileSaver;
|
|
|
|
|
|
import { toast } from 'svelte-sonner';
|
|
|
import { getContext } from 'svelte';
|
|
|
- import { archiveChatById, getAllArchivedChats, getArchivedChatList } from '$lib/apis/chats';
|
|
|
+ import {
|
|
|
+ archiveChatById,
|
|
|
+ getAllArchivedChats,
|
|
|
+ getArchivedChatList,
|
|
|
+ unarchiveAllChats
|
|
|
+ } from '$lib/apis/chats';
|
|
|
|
|
|
import ChatsModal from './ChatsModal.svelte';
|
|
|
import UnarchiveAllConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
|
|
|
+ import Spinner from '../common/Spinner.svelte';
|
|
|
|
|
|
const i18n = getContext('i18n');
|
|
|
|
|
|
export let show = false;
|
|
|
export let onUpdate = () => {};
|
|
|
|
|
|
+ let loading = false;
|
|
|
let chatList = null;
|
|
|
let page = 1;
|
|
|
|
|
@@ -105,13 +112,17 @@
|
|
|
};
|
|
|
|
|
|
const unarchiveAllHandler = async () => {
|
|
|
- const chats = await getAllArchivedChats(localStorage.token);
|
|
|
- for (const chat of chats) {
|
|
|
- await archiveChatById(localStorage.token, chat.id);
|
|
|
+ loading = true;
|
|
|
+ try {
|
|
|
+ await unarchiveAllChats(localStorage.token);
|
|
|
+ toast.success($i18n.t('All chats have been unarchived.'));
|
|
|
+ onUpdate();
|
|
|
+ await init();
|
|
|
+ } catch (error) {
|
|
|
+ toast.error(`${error}`);
|
|
|
+ } finally {
|
|
|
+ loading = false;
|
|
|
}
|
|
|
-
|
|
|
- onUpdate();
|
|
|
- init();
|
|
|
};
|
|
|
|
|
|
const init = async () => {
|
|
@@ -152,15 +163,21 @@
|
|
|
<div class="flex flex-wrap text-sm font-medium gap-1.5 mt-2 m-1 justify-end w-full">
|
|
|
<button
|
|
|
class=" px-3.5 py-1.5 font-medium hover:bg-black/5 dark:hover:bg-white/5 outline outline-1 outline-gray-100 dark:outline-gray-800 rounded-3xl"
|
|
|
+ disabled={loading}
|
|
|
on:click={() => {
|
|
|
showUnarchiveAllConfirmDialog = true;
|
|
|
}}
|
|
|
>
|
|
|
- {$i18n.t('Unarchive All Archived Chats')}
|
|
|
+ {#if loading}
|
|
|
+ <Spinner className="size-4" />
|
|
|
+ {:else}
|
|
|
+ {$i18n.t('Unarchive All Archived Chats')}
|
|
|
+ {/if}
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
class="px-3.5 py-1.5 font-medium hover:bg-black/5 dark:hover:bg-white/5 outline outline-1 outline-gray-100 dark:outline-gray-800 rounded-3xl"
|
|
|
+ disabled={loading}
|
|
|
on:click={() => {
|
|
|
exportChatsHandler();
|
|
|
}}
|