feat/enh: move chats in folder on delete

Co-Authored-By: expruc <25387342+expruc@users.noreply.github.com>
This commit is contained in:
Timothy Jaeryang Baek
2025-11-23 00:01:49 -05:00
parent b2034861ae
commit e6951e804a
5 changed files with 76 additions and 26 deletions

View File

@@ -239,10 +239,13 @@ export const updateFolderItemsById = async (token: string, id: string, items: Fo
return res;
};
export const deleteFolderById = async (token: string, id: string) => {
export const deleteFolderById = async (token: string, id: string, deleteContents: boolean) => {
let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/folders/${id}`, {
const searchParams = new URLSearchParams();
searchParams.append('delete_contents', deleteContents ? 'true' : 'false');
const res = await fetch(`${WEBUI_API_BASE_URL}/folders/${id}?${searchParams.toString()}`, {
method: 'DELETE',
headers: {
Accept: 'application/json',

View File

@@ -31,6 +31,7 @@
let showFolderModal = false;
let showDeleteConfirm = false;
let deleteFolderContents = true;
const updateHandler = async ({ name, meta, data }) => {
if (name === '') {
@@ -98,10 +99,12 @@
};
const deleteHandler = async () => {
const res = await deleteFolderById(localStorage.token, folder.id).catch((error) => {
toast.error(`${error}`);
return null;
});
const res = await deleteFolderById(localStorage.token, folder.id, deleteFolderContents).catch(
(error) => {
toast.error(`${error}`);
return null;
}
);
if (res) {
toast.success($i18n.t('Folder deleted successfully'));
@@ -141,15 +144,22 @@
deleteHandler();
}}
>
<div class=" text-sm text-gray-700 dark:text-gray-300 flex-1 line-clamp-3">
{@html DOMPurify.sanitize(
$i18n.t(
'This will delete <strong>{{NAME}}</strong> and <strong>all its contents</strong>.',
{
NAME: folder.name
}
)
)}
<div class=" text-sm text-gray-700 dark:text-gray-300 flex-1 line-clamp-3 mb-2">
<!-- {$i18n.t('This will delete <strong>{{NAME}}</strong> and <strong>all its contents</strong>.', {
NAME: folders[folderId].name
})} -->
{$i18n.t(`Are you sure you want to delete "{{NAME}}"?`, {
NAME: folders[folderId].name
})}
</div>
<div class="flex items-center gap-1.5">
<input type="checkbox" bind:checked={deleteFolderContents} />
<div class="text-xs text-gray-500">
{$i18n.t('Delete all contents inside this folder')}
</div>
</div>
</DeleteConfirmDialog>

View File

@@ -52,6 +52,8 @@
export let className = '';
export let deleteFolderContents = true;
export let parentDragged = false;
export let onDelete = (e) => {};
@@ -288,10 +290,12 @@
let showDeleteConfirm = false;
const deleteHandler = async () => {
const res = await deleteFolderById(localStorage.token, folderId).catch((error) => {
toast.error(`${error}`);
return null;
});
const res = await deleteFolderById(localStorage.token, folderId, deleteFolderContents).catch(
(error) => {
toast.error(`${error}`);
return null;
}
);
if (res) {
toast.success($i18n.t('Folder deleted successfully'));
@@ -430,12 +434,22 @@
deleteHandler();
}}
>
<div class=" text-sm text-gray-700 dark:text-gray-300 flex-1 line-clamp-3">
{@html DOMPurify.sanitize(
$i18n.t('This will delete <strong>{{NAME}}</strong> and <strong>all its contents</strong>.', {
<div class=" text-sm text-gray-700 dark:text-gray-300 flex-1 line-clamp-3 mb-2">
<!-- {$i18n.t('This will delete <strong>{{NAME}}</strong> and <strong>all its contents</strong>.', {
NAME: folders[folderId].name
})
)}
})} -->
{$i18n.t(`Are you sure you want to delete "{{NAME}}"?`, {
NAME: folders[folderId].name
})}
</div>
<div class="flex items-center gap-1.5">
<input type="checkbox" bind:checked={deleteFolderContents} />
<div class="text-xs text-gray-500">
{$i18n.t('Delete all contents inside this folder')}
</div>
</div>
</DeleteConfirmDialog>