enh: delete notes

This commit is contained in:
Timothy Jaeryang Baek 2025-05-04 17:01:12 +04:00
parent 18149483f2
commit f716968009

View File

@ -31,7 +31,7 @@
import { onMount, getContext } from 'svelte'; import { onMount, getContext } from 'svelte';
import { WEBUI_NAME, config, prompts as _prompts, user } from '$lib/stores'; import { WEBUI_NAME, config, prompts as _prompts, user } from '$lib/stores';
import { createNewNote, getNotes } from '$lib/apis/notes'; import { createNewNote, deleteNoteById, getNotes } from '$lib/apis/notes';
import { capitalizeFirstLetter } from '$lib/utils'; import { capitalizeFirstLetter } from '$lib/utils';
import EllipsisHorizontal from '../icons/EllipsisHorizontal.svelte'; import EllipsisHorizontal from '../icons/EllipsisHorizontal.svelte';
@ -155,6 +155,17 @@
} }
}; };
const deleteNoteHandler = async (id) => {
const res = await deleteNoteById(localStorage.token, id).catch((error) => {
toast.error(`${error}`);
return null;
});
if (res) {
init();
}
};
onMount(async () => { onMount(async () => {
await init(); await init();
loaded = true; loaded = true;
@ -171,7 +182,10 @@
<DeleteConfirmDialog <DeleteConfirmDialog
bind:show={showDeleteConfirm} bind:show={showDeleteConfirm}
title={$i18n.t('Delete note?')} title={$i18n.t('Delete note?')}
on:confirm={() => {}} on:confirm={() => {
deleteNoteHandler(selectedNote.id);
showDeleteConfirm = false;
}}
> >
<div class=" text-sm text-gray-500"> <div class=" text-sm text-gray-500">
{$i18n.t('This will delete')} <span class=" font-semibold">{selectedNote.title}</span>. {$i18n.t('This will delete')} <span class=" font-semibold">{selectedNote.title}</span>.