1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-28 17:29:36 +02:00

Add popup toggle and card carousel for adventure details in map view

This commit is contained in:
Sean Morley 2024-11-02 21:45:23 -04:00
parent 6137411b84
commit 172f07acca

View file

@ -4,6 +4,8 @@
import { t } from 'svelte-i18n'; import { t } from 'svelte-i18n';
import type { Adventure, VisitedRegion } from '$lib/types.js'; import type { Adventure, VisitedRegion } from '$lib/types.js';
import { getAdventureTypeLabel } from '$lib'; import { getAdventureTypeLabel } from '$lib';
import CardCarousel from '$lib/components/CardCarousel.svelte';
import { goto } from '$app/navigation';
export let data; export let data;
let createModalOpen: boolean = false; let createModalOpen: boolean = false;
@ -39,6 +41,8 @@
let newLongitude: number | null = null; let newLongitude: number | null = null;
let newLatitude: number | null = null; let newLatitude: number | null = null;
let openPopupId: string | null = null; // Store the ID of the currently open popup
function addMarker(e: { detail: { lngLat: { lng: any; lat: any } } }) { function addMarker(e: { detail: { lngLat: { lng: any; lat: any } } }) {
newMarker = null; newMarker = null;
newMarker = { lngLat: e.detail.lngLat }; newMarker = { lngLat: e.detail.lngLat };
@ -46,17 +50,17 @@
newLatitude = e.detail.lngLat.lat; newLatitude = e.detail.lngLat.lat;
} }
// let markers = [];
// $: {
// markers = data.props.markers;
// }
function createNewAdventure(event: CustomEvent) { function createNewAdventure(event: CustomEvent) {
adventures = [...adventures, event.detail]; adventures = [...adventures, event.detail];
newMarker = null; newMarker = null;
createModalOpen = false; createModalOpen = false;
} }
let isPopupOpen = false;
function togglePopup() {
isPopupOpen = !isPopupOpen;
}
</script> </script>
<h1 class="text-center font-bold text-4xl">Adventure Map</h1> <h1 class="text-center font-bold text-4xl">Adventure Map</h1>
@ -73,7 +77,6 @@
<span class="label-text mr-1">Planned</span> <span class="label-text mr-1">Planned</span>
<input type="checkbox" bind:checked={showPlanned} class="checkbox checkbox-primary" /> <input type="checkbox" bind:checked={showPlanned} class="checkbox checkbox-primary" />
</label> </label>
<!-- <div class="divider divider-horizontal"></div> -->
<label for="show-geo">Show Visited Regions</label> <label for="show-geo">Show Visited Regions</label>
<input <input
type="checkbox" type="checkbox"
@ -120,37 +123,45 @@
class="grid h-8 w-8 place-items-center rounded-full border border-gray-200 bg-{adventure.is_visited class="grid h-8 w-8 place-items-center rounded-full border border-gray-200 bg-{adventure.is_visited
? 'red' ? 'red'
: 'blue'}-300 text-black shadow-2xl focus:outline-2 focus:outline-black" : 'blue'}-300 text-black shadow-2xl focus:outline-2 focus:outline-black"
on:click={togglePopup}
> >
<span class="text-xl"> <span class="text-xl">
{getAdventureTypeLabel(adventure.type)} {getAdventureTypeLabel(adventure.type)}
</span> </span>
<Popup openOn="click" offset={[0, -10]}> {#if isPopupOpen}
<div class="text-lg text-black font-bold">{adventure.name}</div> <Popup openOn="click" offset={[0, -10]} on:close={() => (isPopupOpen = false)}>
<p class="font-semibold text-black text-md"> <CardCarousel adventures={[adventure]} />
{adventure.is_visited ? $t('adventures.visited') : $t('adventures.planned')} <div class="text-lg text-black font-bold">{adventure.name}</div>
</p> <p class="font-semibold text-black text-md">
<p class="font-semibold text-black text-md"> {adventure.is_visited ? $t('adventures.visited') : $t('adventures.planned')}
{$t(`adventures.activities.${adventure.type}`)}
</p>
{#if adventure.visits && adventure.visits.length > 0}
<p class="text-black text-sm">
{#each adventure.visits as visit}
{visit.start_date
? new Date(visit.start_date).toLocaleDateString(undefined, {
timeZone: 'UTC'
})
: ''}
{visit.end_date && visit.end_date !== '' && visit.end_date !== visit.start_date
? ' - ' +
new Date(visit.end_date).toLocaleDateString(undefined, {
timeZone: 'UTC'
})
: ''}
<br />
{/each}
</p> </p>
{/if} <p class="font-semibold text-black text-md">
</Popup> {$t(`adventures.activities.${adventure.type}`)}
</p>
{#if adventure.visits && adventure.visits.length > 0}
<p class="text-black text-sm">
{#each adventure.visits as visit}
{visit.start_date
? new Date(visit.start_date).toLocaleDateString(undefined, {
timeZone: 'UTC'
})
: ''}
{visit.end_date && visit.end_date !== '' && visit.end_date !== visit.start_date
? ' - ' +
new Date(visit.end_date).toLocaleDateString(undefined, {
timeZone: 'UTC'
})
: ''}
<br />
{/each}
</p>
{/if}
<button
class="btn btn-neutral btn-wide btn-sm mt-4"
on:click={() => goto(`/adventures/${adventure.id}`)}>View Details</button
>
</Popup>
{/if}
</Marker> </Marker>
{/if} {/if}
{/each} {/each}