1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-22 06:19:38 +02:00

Fix location saving

This commit is contained in:
Sean Morley 2024-07-27 09:29:47 -04:00
parent a38887a602
commit 70d08eff8a
4 changed files with 15 additions and 20 deletions

View file

@ -18,6 +18,7 @@
let image: File; let image: File;
import MapMarker from '~icons/mdi/map-marker'; import MapMarker from '~icons/mdi/map-marker';
import Map from '~icons/mdi/map';
import Calendar from '~icons/mdi/calendar'; import Calendar from '~icons/mdi/calendar';
import Notebook from '~icons/mdi/notebook'; import Notebook from '~icons/mdi/notebook';
import ClipboardList from '~icons/mdi/clipboard-list'; import ClipboardList from '~icons/mdi/clipboard-list';
@ -110,10 +111,8 @@
isImageFetcherOpen = false; isImageFetcherOpen = false;
} }
function setLongLat(event: CustomEvent<[number, number]>) { function setLongLat(event: CustomEvent<Adventure>) {
console.log(event.detail); console.log(event.detail);
adventureToEdit.latitude = event.detail[1];
adventureToEdit.longitude = event.detail[0];
isPointModalOpen = false; isPointModalOpen = false;
} }
</script> </script>
@ -121,8 +120,6 @@
{#if isPointModalOpen} {#if isPointModalOpen}
<PointSelectionModal <PointSelectionModal
bind:adventure={adventureToEdit} bind:adventure={adventureToEdit}
longitude={adventureToEdit.longitude}
latitude={adventureToEdit.latitude}
on:close={() => (isPointModalOpen = false)} on:close={() => (isPointModalOpen = false)}
on:submit={setLongLat} on:submit={setLongLat}
query={adventureToEdit.name} query={adventureToEdit.name}
@ -191,7 +188,10 @@
class="btn btn-secondary" class="btn btn-secondary"
on:click={() => (isPointModalOpen = true)} on:click={() => (isPointModalOpen = true)}
> >
{adventureToEdit.latitude && adventureToEdit.longitude ? 'Change' : 'Select'} <Map class="inline-block w-6 h-6" />{adventureToEdit.latitude &&
adventureToEdit.longitude
? 'Change'
: 'Select'}
Location</button Location</button
> >
</div> </div>

View file

@ -161,6 +161,7 @@
function setLongLat(event: CustomEvent<Adventure>) { function setLongLat(event: CustomEvent<Adventure>) {
console.log(event.detail); console.log(event.detail);
isPointModalOpen = false;
} }
</script> </script>
@ -170,8 +171,6 @@
on:close={() => (isPointModalOpen = false)} on:close={() => (isPointModalOpen = false)}
on:submit={setLongLat} on:submit={setLongLat}
bind:adventure={newAdventure} bind:adventure={newAdventure}
latitude={newAdventure.latitude || null}
longitude={newAdventure.longitude || null}
/> />
{/if} {/if}

View file

@ -18,9 +18,6 @@
geocode(); geocode();
} }
export let longitude: number | null = null;
export let latitude: number | null = null;
function addMarker(e: CustomEvent<MouseEvent>) { function addMarker(e: CustomEvent<MouseEvent>) {
markers = []; markers = [];
markers = [...markers, { lngLat: e.detail.lngLat, name: '' }]; markers = [...markers, { lngLat: e.detail.lngLat, name: '' }];
@ -32,10 +29,10 @@
if (modal) { if (modal) {
modal.showModal(); modal.showModal();
} }
if (longitude && latitude) { if (adventure.longitude && adventure.latitude) {
markers = [ markers = [
{ {
lngLat: { lng: longitude, lat: latitude }, lngLat: { lng: adventure.longitude, lat: adventure.latitude },
name: adventure.name, name: adventure.name,
location: adventure.location location: adventure.location
} }
@ -78,11 +75,10 @@
alert('Please select a point on the map'); alert('Please select a point on the map');
return; return;
} }
let coordArray: [number, number] = [markers[0].lngLat.lng, markers[0].lngLat.lat];
console.log(markers[0]); console.log(markers[0]);
adventure.longitude = coordArray[0]; adventure.longitude = markers[0].lngLat.lng;
adventure.latitude = coordArray[1]; adventure.latitude = markers[0].lngLat.lat;
if (!adventure.location) { if (!adventure.location) {
adventure.location = markers[0].location; adventure.location = markers[0].location;
} }

View file

@ -127,8 +127,8 @@
<circle cx="12" cy="12" r="10" stroke="red" stroke-width="2" fill="red" /> <circle cx="12" cy="12" r="10" stroke="red" stroke-width="2" fill="red" />
</svg> </svg>
<Popup openOn="click" offset={[0, -10]}> <Popup openOn="click" offset={[0, -10]}>
<div class="text-lg font-bold">{name}</div> <div class="text-lg text-black font-bold">{name}</div>
<p class="font-semibold text-md">Visited</p> <p class="font-semibold text-black text-md">Visited</p>
</Popup> </Popup>
</Marker> </Marker>
{/if} {/if}
@ -149,8 +149,8 @@
<circle cx="12" cy="12" r="10" stroke="blue" stroke-width="2" fill="blue" /> <circle cx="12" cy="12" r="10" stroke="blue" stroke-width="2" fill="blue" />
</svg> </svg>
<Popup openOn="click" offset={[0, -10]}> <Popup openOn="click" offset={[0, -10]}>
<div class="text-lg font-bold">{name}</div> <div class="text-lg text-black font-bold">{name}</div>
<p class="font-semibold text-md">Planned</p> <p class="font-semibold text-black text-md">Planned</p>
</Popup> </Popup>
</Marker> </Marker>
{/if} {/if}