Skip to content

Commit 7cfbf64

Browse files
committed
Update ManageModal.svelte
feat: Add ConfirmDialog to 'Clear Memory' button
1 parent 6cf0cee commit 7cfbf64

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

src/lib/components/chat/Settings/Personalization/ManageModal.svelte

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import { error } from '@sveltejs/kit';
1313
import EditMemoryModal from './EditMemoryModal.svelte';
1414
import localizedFormat from 'dayjs/plugin/localizedFormat';
15+
import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
1516
1617
const i18n = getContext('i18n');
1718
dayjs.extend(localizedFormat);
@@ -26,6 +27,21 @@
2627
2728
let selectedMemory = null;
2829
30+
let showClearConfirmDialog = false;
31+
32+
let onClearConfirmed = async () => {
33+
const res = await deleteMemoriesByUserId(localStorage.token).catch((error) => {
34+
toast.error(`${error}`);
35+
return null;
36+
});
37+
38+
if (res) {
39+
toast.success($i18n.t('Memory cleared successfully'));
40+
memories = [];
41+
}
42+
showClearConfirmDialog = false;
43+
};
44+
2945
$: if (show && memories.length === 0 && loading) {
3046
(async () => {
3147
memories = await getMemories(localStorage.token);
@@ -175,23 +191,25 @@
175191
>
176192
<button
177193
class=" px-3.5 py-1.5 font-medium text-red-500 hover:bg-black/5 dark:hover:bg-white/5 outline outline-1 outline-red-300 dark:outline-red-800 rounded-3xl"
178-
on:click={async () => {
179-
const res = await deleteMemoriesByUserId(localStorage.token).catch((error) => {
180-
toast.error(`${error}`);
181-
return null;
182-
});
183-
184-
if (res) {
185-
toast.success($i18n.t('Memory cleared successfully'));
186-
memories = [];
187-
}
194+
on:click={() => {
195+
showClearConfirmDialog = true;
188196
}}>{$i18n.t('Clear memory')}</button
189197
>
190198
</div>
191199
</div>
192200
</div>
193201
</Modal>
194202

203+
<ConfirmDialog
204+
title={$i18n.t('Clear Memory')}
205+
message={$i18n.t('Are you sure you want to clear all memories? This action cannot be undone.')}
206+
show={showClearConfirmDialog}
207+
on:confirm={onClearConfirmed}
208+
on:cancel={() => {
209+
showClearConfirmDialog = false;
210+
}}
211+
/>
212+
195213
<AddMemoryModal
196214
bind:show={showAddMemoryModal}
197215
on:save={async () => {

0 commit comments

Comments
 (0)