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();
|
2024-11-03 22:55:38 -05:00
|
|
|
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';
|
2024-12-19 19:07:23 -05:00
|
|
|
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
|
|
|
|
2024-12-19 19:07:23 -05:00
|
|
|
let isWarningModalOpen: boolean = false;
|
|
|
|
|
2024-12-26 21:56:14 -05:00
|
|
|
let unlinked: boolean = false;
|
|
|
|
|
|
|
|
$: {
|
|
|
|
if (collection?.start_date && collection.end_date) {
|
|
|
|
const startOutsideRange =
|
|
|
|
checklist.date &&
|
|
|
|
collection.start_date < checklist.date &&
|
|
|
|
collection.end_date < checklist.date;
|
|
|
|
|
|
|
|
const endOutsideRange =
|
|
|
|
checklist.date &&
|
|
|
|
collection.start_date > checklist.date &&
|
|
|
|
collection.end_date > checklist.date;
|
|
|
|
|
2024-12-26 22:09:17 -05:00
|
|
|
unlinked = !!(startOutsideRange || endOutsideRange || !checklist.date);
|
2024-12-26 21:56:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2024-11-03 22:55:38 -05:00
|
|
|
addToast('success', $t('checklist.checklist_deleted'));
|
2024-12-19 19:07:23 -05:00
|
|
|
isWarningModalOpen = false;
|
2024-08-05 18:48:11 -04:00
|
|
|
dispatch('delete', checklist.id);
|
|
|
|
} else {
|
2024-11-03 22:55:38 -05:00
|
|
|
addToast($t('checklist.checklist_delete_error'), 'error');
|
2024-08-05 18:48:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2024-12-19 19:07:23 -05:00
|
|
|
{#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
|
2025-05-29 17:47:58 -04:00
|
|
|
class="card w-full max-w-md bg-base-300 text-base-content shadow-2xl hover:shadow-3xl transition-all duration-300 border border-base-300 hover:border-primary/20 group"
|
2024-08-05 18:48:11 -04:00
|
|
|
>
|
2025-05-29 17:47:58 -04:00
|
|
|
<div class="card-body p-6 space-y-4">
|
|
|
|
<!-- Header -->
|
|
|
|
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2">
|
|
|
|
<h2 class="text-xl font-bold break-words">{checklist.name}</h2>
|
|
|
|
<div class="flex flex-wrap gap-2">
|
|
|
|
<div class="badge badge-primary">{$t('adventures.checklist')}</div>
|
|
|
|
{#if unlinked}
|
|
|
|
<div class="badge badge-error">{$t('adventures.out_of_range')}</div>
|
|
|
|
{/if}
|
|
|
|
</div>
|
2024-08-05 18:48:11 -04:00
|
|
|
</div>
|
2025-05-29 17:47:58 -04:00
|
|
|
|
|
|
|
<!-- Checklist Stats -->
|
2024-08-05 18:48:11 -04:00
|
|
|
{#if checklist.items.length > 0}
|
2025-05-29 17:47:58 -04:00
|
|
|
<p class="text-sm">
|
2024-11-03 22:55:38 -05:00
|
|
|
{checklist.items.length}
|
|
|
|
{checklist.items.length > 1 ? $t('checklist.items') : $t('checklist.item')}
|
|
|
|
</p>
|
2024-08-05 18:48:11 -04:00
|
|
|
{/if}
|
2025-05-29 17:47:58 -04:00
|
|
|
|
|
|
|
<!-- Date -->
|
2024-08-05 18:48:11 -04:00
|
|
|
{#if checklist.date && checklist.date !== ''}
|
2025-05-29 17:47:58 -04:00
|
|
|
<div class="inline-flex items-center gap-2 text-sm">
|
|
|
|
<Calendar class="w-5 h-5 text-primary" />
|
2024-08-17 08:30:24 -04:00
|
|
|
<p>{new Date(checklist.date).toLocaleDateString(undefined, { timeZone: 'UTC' })}</p>
|
2024-08-05 18:48:11 -04:00
|
|
|
</div>
|
|
|
|
{/if}
|
2025-05-29 17:47:58 -04:00
|
|
|
|
|
|
|
<!-- Actions -->
|
|
|
|
<div class="pt-4 border-t border-base-300 flex justify-end gap-2">
|
|
|
|
<button class="btn btn-neutral btn-sm flex items-center gap-1" on:click={editChecklist}>
|
|
|
|
<Launch class="w-5 h-5" />
|
|
|
|
{$t('notes.open')}
|
2024-08-05 18:48:11 -04:00
|
|
|
</button>
|
2025-05-29 17:47:58 -04:00
|
|
|
{#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"
|
2025-05-29 17:47:58 -04:00
|
|
|
class="btn btn-secondary btn-sm flex items-center gap-1"
|
|
|
|
on:click={() => (isWarningModalOpen = true)}
|
2024-08-05 18:48:11 -04:00
|
|
|
>
|
2025-05-29 17:47:58 -04:00
|
|
|
<TrashCan class="w-5 h-5" />
|
|
|
|
{$t('adventures.delete')}
|
|
|
|
</button>
|
2024-08-05 18:48:11 -04:00
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|