2024-07-08 11:44:39 -04:00
|
|
|
<script lang="ts">
|
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
import { goto } from '$app/navigation';
|
2024-07-18 18:37:46 -04:00
|
|
|
import type { Adventure, User } from '$lib/types';
|
2024-07-08 11:44:39 -04:00
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
|
|
|
import Launch from '~icons/mdi/launch';
|
|
|
|
import FileDocumentEdit from '~icons/mdi/file-document-edit';
|
|
|
|
import TrashCan from '~icons/mdi/trash-can-outline';
|
|
|
|
import Calendar from '~icons/mdi/calendar';
|
|
|
|
import MapMarker from '~icons/mdi/map-marker';
|
|
|
|
import { addToast } from '$lib/toasts';
|
2024-07-15 12:09:20 -04:00
|
|
|
import Link from '~icons/mdi/link-variant';
|
2024-07-16 09:12:53 -04:00
|
|
|
import CheckBold from '~icons/mdi/check-bold';
|
|
|
|
import FormatListBulletedSquare from '~icons/mdi/format-list-bulleted-square';
|
|
|
|
import LinkVariantRemove from '~icons/mdi/link-variant-remove';
|
|
|
|
import Plus from '~icons/mdi/plus';
|
|
|
|
import CollectionLink from './CollectionLink.svelte';
|
2024-07-16 14:50:30 -04:00
|
|
|
import DotsHorizontal from '~icons/mdi/dots-horizontal';
|
2024-08-14 22:17:43 -04:00
|
|
|
import DeleteWarning from './DeleteWarning.svelte';
|
2024-08-19 08:43:43 -04:00
|
|
|
import ImageDisplayModal from './ImageDisplayModal.svelte';
|
2024-07-08 11:44:39 -04:00
|
|
|
|
|
|
|
export let type: string;
|
|
|
|
|
2024-07-18 18:37:46 -04:00
|
|
|
export let user: User | null;
|
|
|
|
|
2024-07-16 09:12:53 -04:00
|
|
|
let isCollectionModalOpen: boolean = false;
|
2024-08-14 22:17:43 -04:00
|
|
|
let isWarningModalOpen: boolean = false;
|
2024-07-16 09:12:53 -04:00
|
|
|
|
2024-07-27 18:42:52 -04:00
|
|
|
let keyword: string = '';
|
2024-08-19 08:43:43 -04:00
|
|
|
let image_url: string | null = null;
|
2024-07-08 11:44:39 -04:00
|
|
|
export let adventure: Adventure;
|
|
|
|
|
2024-07-27 18:42:52 -04:00
|
|
|
if (adventure.type == 'visited') {
|
|
|
|
keyword = 'Adventure';
|
|
|
|
} else if (adventure.type == 'planned') {
|
|
|
|
keyword = 'Adventure';
|
|
|
|
} else if (adventure.type == 'lodging') {
|
|
|
|
keyword = 'Lodging';
|
|
|
|
} else if (adventure.type == 'dining') {
|
|
|
|
keyword = 'Dining';
|
|
|
|
}
|
|
|
|
|
2024-07-18 22:12:47 -04:00
|
|
|
let activityTypes: string[] = [];
|
|
|
|
// makes it reactivty to changes so it updates automatically
|
|
|
|
$: {
|
|
|
|
if (adventure.activity_types) {
|
|
|
|
activityTypes = adventure.activity_types;
|
|
|
|
if (activityTypes.length > 3) {
|
|
|
|
activityTypes = activityTypes.slice(0, 3);
|
|
|
|
let remaining = adventure.activity_types.length - 3;
|
|
|
|
activityTypes.push('+' + remaining);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-08 11:44:39 -04:00
|
|
|
async function deleteAdventure() {
|
|
|
|
let res = await fetch(`/adventures/${adventure.id}?/delete`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (res.ok) {
|
|
|
|
console.log('Adventure deleted');
|
|
|
|
addToast('info', 'Adventure deleted successfully!');
|
|
|
|
dispatch('delete', adventure.id);
|
|
|
|
} else {
|
|
|
|
console.log('Error deleting adventure');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-16 09:12:53 -04:00
|
|
|
async function removeFromCollection() {
|
|
|
|
let res = await fetch(`/api/adventures/${adventure.id}`, {
|
|
|
|
method: 'PATCH',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify({ collection: null })
|
|
|
|
});
|
|
|
|
if (res.ok) {
|
|
|
|
console.log('Adventure removed from collection');
|
|
|
|
addToast('info', 'Adventure removed from collection successfully!');
|
|
|
|
dispatch('delete', adventure.id);
|
|
|
|
} else {
|
|
|
|
console.log('Error removing adventure from collection');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function changeType(newType: string) {
|
|
|
|
return async () => {
|
|
|
|
let res = await fetch(`/api/adventures/${adventure.id}/`, {
|
|
|
|
method: 'PATCH',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify({ type: newType })
|
|
|
|
});
|
|
|
|
if (res.ok) {
|
|
|
|
console.log('Adventure type changed');
|
2024-07-22 10:45:25 -04:00
|
|
|
dispatch('typeChange', adventure.id);
|
2024-07-16 09:12:53 -04:00
|
|
|
addToast('info', 'Adventure type changed successfully!');
|
|
|
|
adventure.type = newType;
|
|
|
|
} else {
|
|
|
|
console.log('Error changing adventure type');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async function linkCollection(event: CustomEvent<number>) {
|
|
|
|
let collectionId = event.detail;
|
|
|
|
let res = await fetch(`/api/adventures/${adventure.id}`, {
|
|
|
|
method: 'PATCH',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify({ collection: collectionId })
|
|
|
|
});
|
|
|
|
if (res.ok) {
|
|
|
|
console.log('Adventure linked to collection');
|
|
|
|
addToast('info', 'Adventure linked to collection successfully!');
|
|
|
|
isCollectionModalOpen = false;
|
|
|
|
dispatch('delete', adventure.id);
|
|
|
|
} else {
|
|
|
|
console.log('Error linking adventure to collection');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-08 11:44:39 -04:00
|
|
|
function editAdventure() {
|
|
|
|
dispatch('edit', adventure);
|
|
|
|
}
|
2024-07-15 12:09:20 -04:00
|
|
|
|
2024-08-17 14:34:14 -04:00
|
|
|
let currentSlide = 0;
|
|
|
|
|
|
|
|
function goToSlide(index: number) {
|
|
|
|
currentSlide = index;
|
|
|
|
}
|
|
|
|
|
2024-07-15 12:09:20 -04:00
|
|
|
function link() {
|
|
|
|
dispatch('link', adventure);
|
|
|
|
}
|
2024-07-08 11:44:39 -04:00
|
|
|
</script>
|
|
|
|
|
2024-07-16 09:12:53 -04:00
|
|
|
{#if isCollectionModalOpen}
|
|
|
|
<CollectionLink on:link={linkCollection} on:close={() => (isCollectionModalOpen = false)} />
|
|
|
|
{/if}
|
|
|
|
|
2024-08-14 22:17:43 -04:00
|
|
|
{#if isWarningModalOpen}
|
|
|
|
<DeleteWarning
|
|
|
|
title="Delete Adventure"
|
|
|
|
button_text="Delete"
|
|
|
|
description="Are you sure you want to delete this adventure? This action cannot be undone."
|
|
|
|
is_warning={false}
|
|
|
|
on:close={() => (isWarningModalOpen = false)}
|
|
|
|
on:confirm={deleteAdventure}
|
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
|
2024-08-19 08:43:43 -04:00
|
|
|
{#if image_url}
|
|
|
|
<ImageDisplayModal image={image_url} on:close={() => (image_url = null)} {adventure} />
|
|
|
|
{/if}
|
|
|
|
|
2024-07-08 11:44:39 -04:00
|
|
|
<div
|
2024-09-06 23:35:48 -04:00
|
|
|
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"
|
2024-07-08 11:44:39 -04:00
|
|
|
>
|
|
|
|
<figure>
|
2024-08-15 21:16:02 -04:00
|
|
|
{#if adventure.images && adventure.images.length > 0}
|
|
|
|
<div class="carousel w-full">
|
|
|
|
{#each adventure.images as image, i}
|
2024-08-17 14:34:14 -04:00
|
|
|
<div
|
|
|
|
class="carousel-item w-full"
|
|
|
|
style="display: {i === currentSlide ? 'block' : 'none'}"
|
|
|
|
>
|
2024-08-19 08:44:00 -04:00
|
|
|
<!-- svelte-ignore a11y-invalid-attribute -->
|
2024-08-19 08:53:37 -04:00
|
|
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
|
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
|
|
<!-- svelte-ignore a11y-missing-attribute -->
|
|
|
|
<a on:click={() => (image_url = image.image)}
|
2024-08-19 08:43:43 -04:00
|
|
|
><img src={image.image} class="w-full h-48 object-cover" alt={adventure.name} /></a
|
|
|
|
>
|
2024-08-17 14:34:14 -04:00
|
|
|
<div class="flex justify-center w-full py-2 gap-2">
|
|
|
|
{#each adventure.images as _, i}
|
|
|
|
<button
|
|
|
|
on:click={() => goToSlide(i)}
|
|
|
|
class="btn btn-xs {i === currentSlide ? 'btn-active' : ''}">{i + 1}</button
|
|
|
|
>
|
|
|
|
{/each}
|
2024-08-15 21:16:02 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
</div>
|
2024-07-08 11:44:39 -04:00
|
|
|
{:else}
|
2024-08-17 14:34:14 -04:00
|
|
|
<!-- svelte-ignore a11y-img-redundant-alt -->
|
2024-07-08 11:44:39 -04:00
|
|
|
<img
|
|
|
|
src={'https://placehold.co/300?text=No%20Image%20Found&font=roboto'}
|
|
|
|
alt="No image available"
|
|
|
|
class="w-full h-48 object-cover"
|
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
</figure>
|
|
|
|
|
|
|
|
<div class="card-body">
|
2024-07-16 15:44:37 -04:00
|
|
|
<div class="flex justify-between">
|
2024-08-08 13:52:55 -04:00
|
|
|
<button
|
|
|
|
on:click={() => goto(`/adventures/${adventure.id}`)}
|
2024-08-13 11:09:49 -04:00
|
|
|
class="text-2xl font-semibold -mt-2 break-words text-wrap hover:underline text-left"
|
2024-08-08 13:52:55 -04:00
|
|
|
>
|
2024-07-16 15:44:37 -04:00
|
|
|
{adventure.name}
|
2024-08-08 13:52:55 -04:00
|
|
|
</button>
|
2024-07-18 22:12:47 -04:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{#if adventure.type == 'visited' && user?.pk == adventure.user_id}
|
|
|
|
<div class="badge badge-primary">Visited</div>
|
2024-07-27 15:41:26 -04:00
|
|
|
{:else if user?.pk == adventure.user_id && adventure.type == 'planned'}
|
2024-07-18 22:12:47 -04:00
|
|
|
<div class="badge badge-secondary">Planned</div>
|
2024-07-27 19:04:55 -04:00
|
|
|
{:else if (user?.pk !== adventure.user_id && adventure.type == 'planned') || adventure.type == 'visited'}
|
|
|
|
<div class="badge badge-secondary">Adventure</div>
|
2024-07-27 15:41:26 -04:00
|
|
|
{:else if user?.pk == adventure.user_id && adventure.type == 'lodging'}
|
|
|
|
<div class="badge badge-success">Lodging</div>
|
2024-07-27 19:04:55 -04:00
|
|
|
{:else if adventure.type == 'dining'}
|
2024-07-27 18:42:52 -04:00
|
|
|
<div class="badge badge-accent">Dining</div>
|
2024-07-18 22:12:47 -04:00
|
|
|
{/if}
|
2024-07-27 15:41:26 -04:00
|
|
|
|
2024-09-06 23:39:37 -04:00
|
|
|
<div class="badge badge-secondary">{adventure.is_public ? 'Public' : 'Private'}</div>
|
2024-07-16 09:26:45 -04:00
|
|
|
</div>
|
2024-07-08 11:44:39 -04:00
|
|
|
{#if adventure.location && adventure.location !== ''}
|
|
|
|
<div class="inline-flex items-center">
|
|
|
|
<MapMarker class="w-5 h-5 mr-1" />
|
|
|
|
<p class="ml-.5">{adventure.location}</p>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
{#if adventure.date && adventure.date !== ''}
|
|
|
|
<div class="inline-flex items-center">
|
|
|
|
<Calendar class="w-5 h-5 mr-1" />
|
2024-08-18 12:30:12 -04:00
|
|
|
<p>
|
|
|
|
{new Date(adventure.date).toLocaleDateString(undefined, {
|
|
|
|
timeZone: 'UTC'
|
|
|
|
})}{adventure.end_date && adventure.end_date !== ''
|
|
|
|
? ' - ' +
|
|
|
|
new Date(adventure.end_date).toLocaleDateString(undefined, { timeZone: 'UTC' })
|
|
|
|
: ''}
|
|
|
|
</p>
|
2024-07-08 11:44:39 -04:00
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
{#if adventure.activity_types && adventure.activity_types.length > 0}
|
|
|
|
<ul class="flex flex-wrap">
|
2024-07-18 22:12:47 -04:00
|
|
|
{#each activityTypes as activity}
|
2024-07-08 11:44:39 -04:00
|
|
|
<div class="badge badge-primary mr-1 text-md font-semibold pb-2 pt-1 mb-1">
|
|
|
|
{activity}
|
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
</ul>
|
|
|
|
{/if}
|
|
|
|
<div class="card-actions justify-end mt-2">
|
2024-07-16 14:50:30 -04:00
|
|
|
<!-- action options dropdown -->
|
2024-07-18 14:55:23 -04:00
|
|
|
{#if type != 'link'}
|
2024-07-18 18:37:46 -04:00
|
|
|
{#if user?.pk == adventure.user_id}
|
|
|
|
<div class="dropdown dropdown-end">
|
|
|
|
<div tabindex="0" role="button" class="btn btn-neutral">
|
|
|
|
<DotsHorizontal class="w-6 h-6" />
|
|
|
|
</div>
|
|
|
|
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
|
|
|
<ul
|
|
|
|
tabindex="0"
|
|
|
|
class="dropdown-content menu bg-base-100 rounded-box z-[1] w-52 p-2 shadow"
|
2024-07-16 14:50:30 -04:00
|
|
|
>
|
2024-07-18 18:37:46 -04:00
|
|
|
<button
|
|
|
|
class="btn btn-neutral mb-2"
|
|
|
|
on:click={() => goto(`/adventures/${adventure.id}`)}
|
|
|
|
><Launch class="w-6 h-6" />Open Details</button
|
2024-07-18 14:55:23 -04:00
|
|
|
>
|
2024-07-18 18:37:46 -04:00
|
|
|
<button class="btn btn-neutral mb-2" on:click={editAdventure}>
|
2024-07-27 18:42:52 -04:00
|
|
|
<FileDocumentEdit class="w-6 h-6" />Edit {keyword}
|
2024-07-18 18:37:46 -04:00
|
|
|
</button>
|
|
|
|
{#if adventure.type == 'visited'}
|
|
|
|
<button class="btn btn-neutral mb-2" on:click={changeType('planned')}
|
|
|
|
><FormatListBulletedSquare class="w-6 h-6" />Change to Plan</button
|
|
|
|
>
|
|
|
|
{/if}
|
|
|
|
{#if adventure.type == 'planned'}
|
|
|
|
<button class="btn btn-neutral mb-2" on:click={changeType('visited')}
|
|
|
|
><CheckBold class="w-6 h-6" />Mark Visited</button
|
|
|
|
>
|
|
|
|
{/if}
|
2024-07-27 15:49:57 -04:00
|
|
|
<!-- remove from adventure -->
|
2024-08-01 11:01:27 -04:00
|
|
|
{#if adventure.collection && (adventure.type == 'visited' || adventure.type == 'planned')}
|
2024-07-18 18:37:46 -04:00
|
|
|
<button class="btn btn-neutral mb-2" on:click={removeFromCollection}
|
|
|
|
><LinkVariantRemove class="w-6 h-6" />Remove from Collection</button
|
|
|
|
>
|
|
|
|
{/if}
|
2024-07-27 15:49:57 -04:00
|
|
|
<!-- change a non adventure to an adventure -->
|
2024-07-27 18:42:52 -04:00
|
|
|
{#if (adventure.collection && adventure.type == 'lodging') || adventure.type == 'dining'}
|
2024-07-27 15:49:57 -04:00
|
|
|
<button class="btn btn-neutral mb-2" on:click={changeType('visited')}
|
|
|
|
><CheckBold class="w-6 h-6" />Change to Visit</button
|
|
|
|
>
|
|
|
|
{/if}
|
2024-07-18 18:37:46 -04:00
|
|
|
{#if !adventure.collection}
|
|
|
|
<button class="btn btn-neutral mb-2" on:click={() => (isCollectionModalOpen = true)}
|
|
|
|
><Plus class="w-6 h-6" />Add to Collection</button
|
|
|
|
>
|
|
|
|
{/if}
|
2024-07-30 08:34:26 -04:00
|
|
|
<button
|
|
|
|
id="delete_adventure"
|
|
|
|
data-umami-event="Delete Adventure"
|
|
|
|
class="btn btn-warning"
|
2024-08-14 22:17:43 -04:00
|
|
|
on:click={() => (isWarningModalOpen = true)}
|
|
|
|
><TrashCan class="w-6 h-6" />Delete</button
|
2024-07-18 14:55:23 -04:00
|
|
|
>
|
2024-07-18 18:37:46 -04:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
{:else}
|
|
|
|
<button class="btn btn-neutral mb-2" on:click={() => goto(`/adventures/${adventure.id}`)}
|
|
|
|
><Launch class="w-6 h-6" /></button
|
|
|
|
>
|
|
|
|
{/if}
|
2024-07-18 14:55:23 -04:00
|
|
|
{/if}
|
|
|
|
{#if type == 'link'}
|
|
|
|
<button class="btn btn-primary" on:click={link}><Link class="w-6 h-6" /></button>
|
|
|
|
{/if}
|
2024-07-08 11:44:39 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|