Update ArchivedChatsModal.svelte
feat: Unarchive All Archived Chats button
This commit is contained in:
1 parent
4616b508b1
commit
f39a523ec0
1 file changed
+37
-5
@@ -15,6 +15,7 @@
|
|||||||
getArchivedChatList
|
getArchivedChatList
|
||||||
} from '$lib/apis/chats';
|
} from '$lib/apis/chats';
|
||||||
import Tooltip from '$lib/components/common/Tooltip.svelte';
|
import Tooltip from '$lib/components/common/Tooltip.svelte';
|
||||||
|
import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
export let show = false;
|
export let show = false;
|
||||||
@@ -23,6 +24,8 @@
|
|||||||
|
|
||||||
let chats = [];
|
let chats = [];
|
||||||
|
|
||||||
|
let unarchiveAllDialogShow = false;
|
||||||
|
|
||||||
const unarchiveChatHandler = async (chatId) => {
|
const unarchiveChatHandler = async (chatId) => {
|
||||||
const res = await archiveChatById(localStorage.token, chatId).catch((error) => {
|
const res = await archiveChatById(localStorage.token, chatId).catch((error) => {
|
||||||
toast.error(error);
|
toast.error(error);
|
||||||
@@ -45,7 +48,14 @@
|
|||||||
let blob = new Blob([JSON.stringify(chats)], {
|
let blob = new Blob([JSON.stringify(chats)], {
|
||||||
type: 'application/json'
|
type: 'application/json'
|
||||||
});
|
});
|
||||||
saveAs(blob, `archived-chat-export-${Date.now()}.json`);
|
saveAs(blob, `${$i18n.t('archived-chat-export')}-${Date.now()}.json`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const unarchiveAllHandler = async () => {
|
||||||
|
for (const chat of chats) {
|
||||||
|
await archiveChatById(localStorage.token, chat.id);
|
||||||
|
}
|
||||||
|
chats = await getArchivedChatList(localStorage.token);
|
||||||
};
|
};
|
||||||
|
|
||||||
$: if (show) {
|
$: if (show) {
|
||||||
@@ -72,7 +82,9 @@
|
|||||||
class="w-5 h-5"
|
class="w-5 h-5"
|
||||||
>
|
>
|
||||||
<path
|
<path
|
||||||
|
fill-rule="evenodd"
|
||||||
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
|
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
|
||||||
|
clip-rule="evenodd"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
@@ -144,7 +156,7 @@
|
|||||||
|
|
||||||
<td class="px-3 py-1 text-right">
|
<td class="px-3 py-1 text-right">
|
||||||
<div class="flex justify-end w-full">
|
<div class="flex justify-end w-full">
|
||||||
<Tooltip content="Unarchive Chat">
|
<Tooltip content={$i18n.t('Unarchive Chat')}>
|
||||||
<button
|
<button
|
||||||
class="self-center w-fit text-sm px-2 py-2 hover:bg-black/5 dark:hover:bg-white/5 rounded-xl"
|
class="self-center w-fit text-sm px-2 py-2 hover:bg-black/5 dark:hover:bg-white/5 rounded-xl"
|
||||||
on:click={async () => {
|
on:click={async () => {
|
||||||
@@ -168,7 +180,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
||||||
<Tooltip content="Delete Chat">
|
<Tooltip content={$i18n.t('Delete Chat')}>
|
||||||
<button
|
<button
|
||||||
class="self-center w-fit text-sm px-2 py-2 hover:bg-black/5 dark:hover:bg-white/5 rounded-xl"
|
class="self-center w-fit text-sm px-2 py-2 hover:bg-black/5 dark:hover:bg-white/5 rounded-xl"
|
||||||
on:click={async () => {
|
on:click={async () => {
|
||||||
@@ -204,9 +216,29 @@
|
|||||||
<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-300 dark:outline-gray-800 rounded-3xl"
|
class=" px-3.5 py-1.5 font-medium hover:bg-black/5 dark:hover:bg-white/5 outline outline-1 outline-gray-300 dark:outline-gray-800 rounded-3xl"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
exportChatsHandler();
|
unarchiveAllDialogShow = true;
|
||||||
}}>Export All Archived Chats</button
|
}}
|
||||||
>
|
>
|
||||||
|
{$i18n.t('Unarchive All Archived Chats')}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<ConfirmDialog
|
||||||
|
bind:show={unarchiveAllDialogShow}
|
||||||
|
message={$i18n.t('Are you sure you want to unarchive all archived chats?')}
|
||||||
|
confirmLabel={$i18n.t('Unarchive All')}
|
||||||
|
on:confirm={() => {
|
||||||
|
unarchiveAllHandler();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<button
|
||||||
|
class="px-3.5 py-1.5 font-medium hover:bg-black/5 dark:hover:bg-white/5 outline outline-1 outline-gray-300 dark:outline-gray-800 rounded-3xl"
|
||||||
|
on:click={() => {
|
||||||
|
exportChatsHandler();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{$i18n.t('Export All Archived Chats')}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
|
|||||||
Reference in new issue
Block a user