2024-08-03 22:03:27 -04:00
|
|
|
<script lang="ts">
|
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
import { addToast } from '$lib/toasts';
|
|
|
|
import type { Note } from '$lib/types';
|
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
|
|
|
import Launch from '~icons/mdi/launch';
|
2024-08-04 12:37:04 -04:00
|
|
|
import TrashCan from '~icons/mdi/trash-can';
|
2024-08-03 22:03:27 -04:00
|
|
|
|
|
|
|
export let note: Note;
|
|
|
|
|
|
|
|
function editNote() {
|
|
|
|
dispatch('edit', note);
|
|
|
|
}
|
2024-08-04 12:37:04 -04:00
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
2024-08-03 22:03:27 -04:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div
|
|
|
|
class="card w-full max-w-xs sm:max-w-sm md:max-w-md lg:max-w-md xl:max-w-md bg-primary-content shadow-xl overflow-hidden text-base-content"
|
|
|
|
>
|
|
|
|
<div class="card-body">
|
|
|
|
<h2 class="card-title overflow-ellipsis">{note.name}</h2>
|
|
|
|
<div class="card-actions justify-end">
|
2024-08-04 09:56:58 -04:00
|
|
|
<!-- <button class="btn btn-neutral mb-2" on:click={() => goto(`/notes/${note.id}`)}
|
2024-08-03 22:03:27 -04:00
|
|
|
><Launch class="w-6 h-6" />Open Details</button
|
2024-08-04 09:56:58 -04:00
|
|
|
> -->
|
2024-08-03 22:03:27 -04:00
|
|
|
<button class="btn btn-neutral mb-2" on:click={editNote}>
|
2024-08-04 09:56:58 -04:00
|
|
|
<Launch class="w-6 h-6" />Open
|
2024-08-03 22:03:27 -04:00
|
|
|
</button>
|
2024-08-04 12:37:04 -04:00
|
|
|
<button
|
|
|
|
id="delete_adventure"
|
|
|
|
data-umami-event="Delete Adventure"
|
|
|
|
class="btn btn-warning"
|
|
|
|
on:click={deleteNote}><TrashCan class="w-6 h-6" />Delete</button
|
|
|
|
>
|
2024-08-03 22:03:27 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|