2024-07-10 13:36:51 -04:00
|
|
|
<script lang="ts">
|
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
|
2024-07-10 13:49:40 -04:00
|
|
|
import Launch from '~icons/mdi/launch';
|
|
|
|
import TrashCanOutline from '~icons/mdi/trash-can-outline';
|
|
|
|
|
2024-07-15 18:01:49 -04:00
|
|
|
import FileDocumentEdit from '~icons/mdi/file-document-edit';
|
|
|
|
|
2024-07-10 13:36:51 -04:00
|
|
|
import { goto } from '$app/navigation';
|
2024-07-15 09:36:07 -04:00
|
|
|
import type { Collection } from '$lib/types';
|
2024-07-15 12:09:20 -04:00
|
|
|
import { addToast } from '$lib/toasts';
|
2024-07-16 09:12:53 -04:00
|
|
|
|
|
|
|
import Plus from '~icons/mdi/plus';
|
|
|
|
|
2024-07-10 13:36:51 -04:00
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
2024-07-16 09:26:45 -04:00
|
|
|
export let type: String | undefined | null;
|
2024-07-16 09:12:53 -04:00
|
|
|
|
2024-07-10 13:36:51 -04:00
|
|
|
// export let type: String;
|
|
|
|
|
2024-07-15 18:01:49 -04:00
|
|
|
function editAdventure() {
|
|
|
|
dispatch('edit', collection);
|
|
|
|
}
|
|
|
|
|
2024-07-15 09:36:07 -04:00
|
|
|
export let collection: Collection;
|
2024-07-10 13:36:51 -04:00
|
|
|
|
2024-07-15 12:09:20 -04:00
|
|
|
async function deleteCollection() {
|
|
|
|
let res = await fetch(`/collections/${collection.id}?/delete`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (res.ok) {
|
|
|
|
console.log('Collection deleted');
|
|
|
|
addToast('info', 'Adventure deleted successfully!');
|
|
|
|
dispatch('delete', collection.id);
|
|
|
|
} else {
|
|
|
|
console.log('Error deleting adventure');
|
|
|
|
}
|
|
|
|
}
|
2024-07-10 13:36:51 -04:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div
|
|
|
|
class="card min-w-max lg:w-96 md:w-80 sm:w-60 xs:w-40 bg-primary-content shadow-xl overflow-hidden text-base-content"
|
|
|
|
>
|
|
|
|
<div class="card-body">
|
2024-07-15 09:36:07 -04:00
|
|
|
<h2 class="card-title overflow-ellipsis">{collection.name}</h2>
|
|
|
|
<p>{collection.adventures.length} Adventures</p>
|
2024-07-27 14:26:15 -04:00
|
|
|
{#if collection.start_date && collection.end_date}
|
|
|
|
<p>
|
2024-07-27 14:44:15 -04:00
|
|
|
Dates: {new Date(collection.start_date).toLocaleDateString('en-US', { timeZone: 'UTC' })} - {new Date(
|
2024-07-27 14:26:15 -04:00
|
|
|
collection.end_date
|
2024-07-27 14:44:15 -04:00
|
|
|
).toLocaleDateString('en-US', { timeZone: 'UTC' })}
|
2024-07-27 14:26:15 -04:00
|
|
|
</p>
|
|
|
|
<!-- display the duration in days -->
|
|
|
|
<p>
|
|
|
|
Duration: {Math.floor(
|
|
|
|
(new Date(collection.end_date).getTime() - new Date(collection.start_date).getTime()) /
|
|
|
|
(1000 * 60 * 60 * 24)
|
2024-07-27 14:38:43 -04:00
|
|
|
) + 1}{' '}
|
2024-07-27 14:26:15 -04:00
|
|
|
days
|
|
|
|
</p>{/if}
|
2024-08-04 21:30:11 -04:00
|
|
|
<div class="badge badge-neutral">{collection.is_public ? 'Public' : 'Private'}</div>
|
2024-07-10 13:36:51 -04:00
|
|
|
<div class="card-actions justify-end">
|
2024-07-16 09:12:53 -04:00
|
|
|
{#if type != 'link'}
|
|
|
|
<button on:click={deleteCollection} class="btn btn-secondary"
|
|
|
|
><TrashCanOutline class="w-5 h-5 mr-1" /></button
|
|
|
|
>
|
|
|
|
<button class="btn btn-primary" on:click={editAdventure}>
|
|
|
|
<FileDocumentEdit class="w-6 h-6" />
|
|
|
|
</button>
|
|
|
|
<button class="btn btn-primary" on:click={() => goto(`/collections/${collection.id}`)}
|
|
|
|
><Launch class="w-5 h-5 mr-1" /></button
|
|
|
|
>
|
|
|
|
{/if}
|
|
|
|
{#if type == 'link'}
|
|
|
|
<button class="btn btn-primary" on:click={() => dispatch('link', collection.id)}>
|
|
|
|
<Plus class="w-5 h-5 mr-1" />
|
|
|
|
</button>
|
|
|
|
{/if}
|
2024-07-10 13:36:51 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|