mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-23 23:09:37 +02:00
chore: Add delete functionality to NoteCard component
This commit is contained in:
parent
7c2b0e927d
commit
89bf310340
3 changed files with 35 additions and 16 deletions
|
@ -6,13 +6,25 @@
|
|||
const dispatch = createEventDispatcher();
|
||||
|
||||
import Launch from '~icons/mdi/launch';
|
||||
import FileDocumentEdit from '~icons/mdi/file-document-edit';
|
||||
import TrashCan from '~icons/mdi/trash-can';
|
||||
|
||||
export let note: Note;
|
||||
|
||||
function editNote() {
|
||||
dispatch('edit', note);
|
||||
}
|
||||
|
||||
async function deleteNote() {
|
||||
const res = await fetch(`/api/notes/${note.id}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
if (res.ok) {
|
||||
addToast('success', 'Note deleted successfully');
|
||||
dispatch('delete', note.id);
|
||||
} else {
|
||||
addToast('Failed to delete note', 'error');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
|
@ -27,6 +39,12 @@
|
|||
<button class="btn btn-neutral mb-2" on:click={editNote}>
|
||||
<Launch class="w-6 h-6" />Open
|
||||
</button>
|
||||
<button
|
||||
id="delete_adventure"
|
||||
data-umami-event="Delete Adventure"
|
||||
class="btn btn-warning"
|
||||
on:click={deleteNote}><TrashCan class="w-6 h-6" />Delete</button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue