mirror of
https://github.com/open-webui/open-webui
synced 2025-06-11 00:49:44 +00:00
Merge pull request #10786 from silentoplayz/confirm-clear-for-memories
feat: Confirmation prompt on 'Clear' for memories
This commit is contained in:
commit
c883368842
@ -12,6 +12,7 @@
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import EditMemoryModal from './EditMemoryModal.svelte';
|
import EditMemoryModal from './EditMemoryModal.svelte';
|
||||||
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
||||||
|
import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
|
||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
dayjs.extend(localizedFormat);
|
dayjs.extend(localizedFormat);
|
||||||
@ -26,6 +27,21 @@
|
|||||||
|
|
||||||
let selectedMemory = null;
|
let selectedMemory = null;
|
||||||
|
|
||||||
|
let showClearConfirmDialog = false;
|
||||||
|
|
||||||
|
let onClearConfirmed = async () => {
|
||||||
|
const res = await deleteMemoriesByUserId(localStorage.token).catch((error) => {
|
||||||
|
toast.error(`${error}`);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res && memories.length > 0) {
|
||||||
|
toast.success($i18n.t('Memory cleared successfully'));
|
||||||
|
memories = [];
|
||||||
|
}
|
||||||
|
showClearConfirmDialog = false;
|
||||||
|
};
|
||||||
|
|
||||||
$: if (show && memories.length === 0 && loading) {
|
$: if (show && memories.length === 0 && loading) {
|
||||||
(async () => {
|
(async () => {
|
||||||
memories = await getMemories(localStorage.token);
|
memories = await getMemories(localStorage.token);
|
||||||
@ -175,15 +191,11 @@
|
|||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
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"
|
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"
|
||||||
on:click={async () => {
|
on:click={() => {
|
||||||
const res = await deleteMemoriesByUserId(localStorage.token).catch((error) => {
|
if (memories.length > 0) {
|
||||||
toast.error(`${error}`);
|
showClearConfirmDialog = true;
|
||||||
return null;
|
} else {
|
||||||
});
|
toast.error($i18n.t('No memories to clear'));
|
||||||
|
|
||||||
if (res) {
|
|
||||||
toast.success($i18n.t('Memory cleared successfully'));
|
|
||||||
memories = [];
|
|
||||||
}
|
}
|
||||||
}}>{$i18n.t('Clear memory')}</button
|
}}>{$i18n.t('Clear memory')}</button
|
||||||
>
|
>
|
||||||
@ -192,6 +204,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
<ConfirmDialog
|
||||||
|
title={$i18n.t('Clear Memory')}
|
||||||
|
message={$i18n.t('Are you sure you want to clear all memories? This action cannot be undone.')}
|
||||||
|
show={showClearConfirmDialog}
|
||||||
|
on:confirm={onClearConfirmed}
|
||||||
|
on:cancel={() => {
|
||||||
|
showClearConfirmDialog = false;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
<AddMemoryModal
|
<AddMemoryModal
|
||||||
bind:show={showAddMemoryModal}
|
bind:show={showAddMemoryModal}
|
||||||
on:save={async () => {
|
on:save={async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user