1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-24 23:39:37 +02:00
AdventureLog/frontend/src/lib/components/ChecklistCard.svelte

85 lines
2.5 KiB
Svelte
Raw Normal View History

2024-08-05 18:48:11 -04:00
<script lang="ts">
import { addToast } from '$lib/toasts';
2024-09-09 13:31:00 -04:00
import type { Checklist, Collection, User } from '$lib/types';
2024-08-05 18:48:11 -04:00
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
import { t } from 'svelte-i18n';
2024-08-05 18:48:11 -04:00
import Launch from '~icons/mdi/launch';
import TrashCan from '~icons/mdi/trash-can';
import Calendar from '~icons/mdi/calendar';
import DeleteWarning from './DeleteWarning.svelte';
2024-08-05 18:48:11 -04:00
export let checklist: Checklist;
export let user: User | null = null;
2024-09-09 13:31:00 -04:00
export let collection: Collection | null = null;
2024-08-05 18:48:11 -04:00
let isWarningModalOpen: boolean = false;
2024-08-05 21:36:38 -04:00
function editChecklist() {
2024-08-05 18:48:11 -04:00
dispatch('edit', checklist);
}
async function deleteChecklist() {
const res = await fetch(`/api/checklists/${checklist.id}`, {
method: 'DELETE'
});
if (res.ok) {
addToast('success', $t('checklist.checklist_deleted'));
isWarningModalOpen = false;
2024-08-05 18:48:11 -04:00
dispatch('delete', checklist.id);
} else {
addToast($t('checklist.checklist_delete_error'), 'error');
2024-08-05 18:48:11 -04:00
}
}
</script>
{#if isWarningModalOpen}
<DeleteWarning
title={$t('adventures.delete_checklist')}
button_text="Delete"
description={$t('adventures.checklist_delete_confirm')}
is_warning={false}
on:close={() => (isWarningModalOpen = false)}
on:confirm={deleteChecklist}
/>
{/if}
2024-08-05 18:48:11 -04:00
<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-neutral text-neutral-content shadow-xl overflow-hidden"
2024-08-05 18:48:11 -04:00
>
<div class="card-body">
<div class="flex justify-between">
<h2 class="text-2xl font-semibold -mt-2 break-words text-wrap">
{checklist.name}
</h2>
</div>
<div class="badge badge-primary">{$t('adventures.checklist')}</div>
2024-08-05 18:48:11 -04:00
{#if checklist.items.length > 0}
<p>
{checklist.items.length}
{checklist.items.length > 1 ? $t('checklist.items') : $t('checklist.item')}
</p>
2024-08-05 18:48:11 -04:00
{/if}
{#if checklist.date && checklist.date !== ''}
<div class="inline-flex items-center">
<Calendar class="w-5 h-5 mr-1" />
<p>{new Date(checklist.date).toLocaleDateString(undefined, { timeZone: 'UTC' })}</p>
2024-08-05 18:48:11 -04:00
</div>
{/if}
<div class="card-actions justify-end">
2024-09-09 13:31:00 -04:00
<button class="btn btn-neutral-200 mb-2" on:click={editChecklist}>
<Launch class="w-6 h-6" />{$t('notes.open')}
2024-08-05 18:48:11 -04:00
</button>
{#if checklist.user_id == user?.uuid || (collection && user && collection.shared_with.includes(user.uuid))}
2024-08-05 18:48:11 -04:00
<button
id="delete_adventure"
data-umami-event="Delete Checklist"
class="btn btn-warning"
on:click={() => (isWarningModalOpen = true)}><TrashCan class="w-6 h-6" /></button
2024-08-05 18:48:11 -04:00
>
{/if}
</div>
</div>
</div>