From 167154bed483f2635c2586e9a5de54ebf8fe8f0b Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Sat, 17 Aug 2024 14:21:55 -0400 Subject: [PATCH] chore: Refactor adventure form components and improve image handling --- .../src/lib/components/EditAdventure.svelte | 9 +- .../src/lib/components/NewAdventure.svelte | 82 ++++++++++++------- 2 files changed, 59 insertions(+), 32 deletions(-) diff --git a/frontend/src/lib/components/EditAdventure.svelte b/frontend/src/lib/components/EditAdventure.svelte index e68ad1e..44b5cb3 100644 --- a/frontend/src/lib/components/EditAdventure.svelte +++ b/frontend/src/lib/components/EditAdventure.svelte @@ -22,6 +22,8 @@ export let startDate: string | null = null; export let endDate: string | null = null; + let noPlaces: boolean = false; + export let adventureToEdit: Adventure; images = adventureToEdit.images || []; @@ -86,6 +88,11 @@ console.log(res); let data = (await res.json()) as OpenStreetMapPlace[]; places = data; + if (data.length === 0) { + noPlaces = true; + } else { + noPlaces = false; + } } async function reverseGeocode() { @@ -395,7 +402,7 @@ {/each} - {:else} + {:else if noPlaces}

No results found

{/if} diff --git a/frontend/src/lib/components/NewAdventure.svelte b/frontend/src/lib/components/NewAdventure.svelte index 48239db..1e10f46 100644 --- a/frontend/src/lib/components/NewAdventure.svelte +++ b/frontend/src/lib/components/NewAdventure.svelte @@ -24,6 +24,9 @@ export let startDate: string | null = null; export let endDate: string | null = null; + let noPlaces: boolean = false; + let wikiError: string = ''; + let newAdventure: Adventure = { id: '', type: type, @@ -79,6 +82,12 @@ console.log(res); let data = (await res.json()) as OpenStreetMapPlace[]; places = data; + + if (data.length === 0) { + noPlaces = true; + } else { + noPlaces = false; + } } async function reverseGeocode() { @@ -121,13 +130,16 @@ } } - // async function generateDesc() { - // let res = await fetch(`/api/generate/desc/?name=${newAdventure.name}`); - // let data = await res.json(); - // if (data.extract) { - // newAdventure.description = data.extract; - // } - // } + async function generateDesc() { + let res = await fetch(`/api/generate/desc/?name=${newAdventure.name}`); + let data = await res.json(); + if (data.extract && data.extract.length > 0) { + newAdventure.description = data.extract; + wikiError = ''; + } else { + wikiError = 'No description found'; + } + } function addMarker(e: CustomEvent) { markers = []; @@ -176,7 +188,7 @@