Skip to content

Commit 61558d5

Browse files
committed
refac
1 parent 0f8d798 commit 61558d5

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/lib/components/layout/Sidebar/ChatItem.svelte

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@
140140
}
141141
};
142142
143+
let deleting = false;
144+
143145
const deleteChatHandler = async (id) => {
146+
if (deleting) return;
147+
deleting = true;
148+
144149
const res = await deleteChatById(localStorage.token, id).catch((error) => {
145150
toast.error(`${error}`);
146151
return null;
@@ -157,9 +162,16 @@
157162
158163
dispatch('change');
159164
}
165+
166+
deleting = false;
160167
};
161168
169+
let archiving = false;
170+
162171
const archiveChatHandler = async (id) => {
172+
if (archiving) return;
173+
archiving = true;
174+
163175
try {
164176
await archiveChatById(localStorage.token, id);
165177
@@ -173,6 +185,8 @@
173185
} catch (error) {
174186
console.error('Error archiving chat:', error);
175187
toast.error($i18n.t('Failed to archive chat.'));
188+
} finally {
189+
archiving = false;
176190
}
177191
};
178192
@@ -537,7 +551,8 @@
537551
<div class=" flex items-center self-center space-x-1.5">
538552
<Tooltip content={$i18n.t('Archive')} className="flex items-center">
539553
<button
540-
class=" self-center dark:hover:text-white transition"
554+
class=" self-center dark:hover:text-white transition disabled:cursor-not-allowed"
555+
disabled={archiving}
541556
on:click={() => {
542557
archiveChatHandler(id);
543558
}}
@@ -549,7 +564,8 @@
549564

550565
<Tooltip content={$i18n.t('Delete')}>
551566
<button
552-
class=" self-center dark:hover:text-white transition"
567+
class=" self-center dark:hover:text-white transition disabled:cursor-not-allowed"
568+
disabled={deleting}
553569
on:click={() => {
554570
deleteChatHandler(id);
555571
}}

0 commit comments

Comments
 (0)