2024-08-03 22:03:27 -04:00
|
|
|
<script lang="ts">
|
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
import { addToast } from '$lib/toasts';
|
2024-08-04 13:33:49 -04:00
|
|
|
import type { Note, User } from '$lib/types';
|
2024-08-03 22:03:27 -04:00
|
|
|
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-05 18:48:11 -04:00
|
|
|
import Calendar from '~icons/mdi/calendar';
|
2024-08-03 22:03:27 -04:00
|
|
|
|
|
|
|
export let note: Note;
|
2024-08-04 13:33:49 -04:00
|
|
|
export let user: User | null = null;
|
2024-08-03 22:03:27 -04:00
|
|
|
|
|
|
|
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">
|
2024-08-05 18:48:11 -04:00
|
|
|
<div class="flex justify-between">
|
|
|
|
<h2 class="text-2xl font-semibold -mt-2 break-words text-wrap">
|
|
|
|
{note.name}
|
|
|
|
</h2>
|
|
|
|
</div>
|
|
|
|
<div class="badge badge-neutral">Note</div>
|
2024-08-04 21:50:15 -04:00
|
|
|
{#if note.links && note.links.length > 0}
|
2024-08-05 21:36:38 -04:00
|
|
|
<p>{note.links.length} {note.links.length > 1 ? 'Links' : 'Link'}</p>
|
2024-08-04 21:50:15 -04:00
|
|
|
{/if}
|
2024-08-05 18:48:11 -04:00
|
|
|
{#if note.date && note.date !== ''}
|
|
|
|
<div class="inline-flex items-center">
|
|
|
|
<Calendar class="w-5 h-5 mr-1" />
|
2024-08-17 08:30:24 -04:00
|
|
|
<p>{new Date(note.date).toLocaleDateString(undefined, { timeZone: 'UTC' })}</p>
|
2024-08-05 18:48:11 -04:00
|
|
|
</div>
|
|
|
|
{/if}
|
2024-08-03 22:03:27 -04:00
|
|
|
<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 13:33:49 -04:00
|
|
|
{#if note.user_id == user?.pk}
|
|
|
|
<button
|
|
|
|
id="delete_adventure"
|
|
|
|
data-umami-event="Delete Adventure"
|
|
|
|
class="btn btn-warning"
|
2024-08-04 21:30:11 -04:00
|
|
|
on:click={deleteNote}><TrashCan class="w-6 h-6" /></button
|
2024-08-04 13:33:49 -04:00
|
|
|
>
|
|
|
|
{/if}
|
2024-08-03 22:03:27 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|