mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-22 22:39:36 +02:00
Wikipedia description fetch
This commit is contained in:
parent
cfe14b3708
commit
add2e2bafa
2 changed files with 212 additions and 194 deletions
|
@ -23,6 +23,8 @@
|
||||||
export let startDate: string | null = null;
|
export let startDate: string | null = null;
|
||||||
export let endDate: string | null = null;
|
export let endDate: string | null = null;
|
||||||
|
|
||||||
|
let wikiError: string = '';
|
||||||
|
|
||||||
let noPlaces: boolean = false;
|
let noPlaces: boolean = false;
|
||||||
|
|
||||||
export let adventureToEdit: Adventure | null = null;
|
export let adventureToEdit: Adventure | null = null;
|
||||||
|
@ -57,7 +59,8 @@
|
||||||
lngLat: { lng: adventure.longitude, lat: adventure.latitude },
|
lngLat: { lng: adventure.longitude, lat: adventure.latitude },
|
||||||
location: adventure.location || '',
|
location: adventure.location || '',
|
||||||
name: adventure.name,
|
name: adventure.name,
|
||||||
activity_type: ''
|
activity_type: '',
|
||||||
|
lng: 0
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -210,7 +213,8 @@
|
||||||
lngLat: { lng: longitude, lat: latitude },
|
lngLat: { lng: longitude, lat: latitude },
|
||||||
location: data[0]?.display_name || '',
|
location: data[0]?.display_name || '',
|
||||||
name: data[0]?.name || '',
|
name: data[0]?.name || '',
|
||||||
activity_type: data[0]?.type || ''
|
activity_type: data[0]?.type || '',
|
||||||
|
lng: 0
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -240,17 +244,28 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// async function generateDesc() {
|
async function generateDesc() {
|
||||||
// let res = await fetch(`/api/generate/desc/?name=${adventureToEdit.name}`);
|
let res = await fetch(`/api/generate/desc/?name=${adventure.name}`);
|
||||||
// let data = await res.json();
|
let data = await res.json();
|
||||||
// if (data.extract) {
|
if (data.extract?.length > 0) {
|
||||||
// adventureToEdit.description = data.extract;
|
adventure.description = data.extract;
|
||||||
// }
|
} else {
|
||||||
// }
|
wikiError = 'No description found';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function addMarker(e: CustomEvent<any>) {
|
function addMarker(e: CustomEvent<any>) {
|
||||||
markers = [];
|
markers = [];
|
||||||
markers = [...markers, { lngLat: e.detail.lngLat, name: '', location: '', activity_type: '' }];
|
markers = [
|
||||||
|
...markers,
|
||||||
|
{
|
||||||
|
lngLat: e.detail.lngLat,
|
||||||
|
name: '',
|
||||||
|
location: '',
|
||||||
|
activity_type: '',
|
||||||
|
lng: 0
|
||||||
|
}
|
||||||
|
];
|
||||||
console.log(markers);
|
console.log(markers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,199 +408,206 @@
|
||||||
bind:value={adventure.description}
|
bind:value={adventure.description}
|
||||||
class="textarea textarea-bordered w-full h-32"
|
class="textarea textarea-bordered w-full h-32"
|
||||||
></textarea>
|
></textarea>
|
||||||
</div>
|
<div class="mt-2">
|
||||||
<div>
|
<button type="button" class="btn btn-neutral" on:click={generateDesc}
|
||||||
<label for="activity_types">Activity Types</label><br />
|
>Generate Description</button
|
||||||
<input
|
>
|
||||||
type="text"
|
<p class="text-red-500">{wikiError}</p>
|
||||||
id="activity_types"
|
|
||||||
name="activity_types"
|
|
||||||
hidden
|
|
||||||
bind:value={adventure.activity_types}
|
|
||||||
class="input input-bordered w-full"
|
|
||||||
/>
|
|
||||||
<ActivityComplete bind:activities={adventure.activity_types} />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label for="rating"
|
|
||||||
>Rating <iconify-icon icon="mdi:star" class="text-xl -mb-1"></iconify-icon></label
|
|
||||||
><br />
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
min="0"
|
|
||||||
max="5"
|
|
||||||
hidden
|
|
||||||
bind:value={adventure.rating}
|
|
||||||
id="rating"
|
|
||||||
name="rating"
|
|
||||||
class="input input-bordered w-full max-w-xs mt-1"
|
|
||||||
/>
|
|
||||||
<div class="rating -ml-3 mt-1">
|
|
||||||
<input
|
|
||||||
type="radio"
|
|
||||||
name="rating-2"
|
|
||||||
class="rating-hidden"
|
|
||||||
checked={Number.isNaN(adventure.rating)}
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="radio"
|
|
||||||
name="rating-2"
|
|
||||||
class="mask mask-star-2 bg-orange-400"
|
|
||||||
on:click={() => (adventure.rating = 1)}
|
|
||||||
checked={adventure.rating === 1}
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="radio"
|
|
||||||
name="rating-2"
|
|
||||||
class="mask mask-star-2 bg-orange-400"
|
|
||||||
on:click={() => (adventure.rating = 2)}
|
|
||||||
checked={adventure.rating === 2}
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="radio"
|
|
||||||
name="rating-2"
|
|
||||||
class="mask mask-star-2 bg-orange-400"
|
|
||||||
on:click={() => (adventure.rating = 3)}
|
|
||||||
checked={adventure.rating === 3}
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="radio"
|
|
||||||
name="rating-2"
|
|
||||||
class="mask mask-star-2 bg-orange-400"
|
|
||||||
on:click={() => (adventure.rating = 4)}
|
|
||||||
checked={adventure.rating === 4}
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="radio"
|
|
||||||
name="rating-2"
|
|
||||||
class="mask mask-star-2 bg-orange-400"
|
|
||||||
on:click={() => (adventure.rating = 5)}
|
|
||||||
checked={adventure.rating === 5}
|
|
||||||
/>
|
|
||||||
{#if adventure.rating}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="btn btn-sm btn-error ml-2"
|
|
||||||
on:click={() => (adventure.rating = NaN)}
|
|
||||||
>
|
|
||||||
Remove
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div class="mt-2">
|
<label for="activity_types">Activity Types</label><br />
|
||||||
<div>
|
<input
|
||||||
<label for="is_public"
|
type="text"
|
||||||
>Public <Earth class="inline-block -mt-1 mb-1 w-6 h-6" /></label
|
id="activity_types"
|
||||||
><br />
|
name="activity_types"
|
||||||
<input
|
hidden
|
||||||
type="checkbox"
|
bind:value={adventure.activity_types}
|
||||||
class="toggle toggle-primary"
|
class="input input-bordered w-full"
|
||||||
id="is_public"
|
/>
|
||||||
name="is_public"
|
<ActivityComplete bind:activities={adventure.activity_types} />
|
||||||
bind:checked={adventure.is_public}
|
</div>
|
||||||
/>
|
<div>
|
||||||
|
<label for="rating"
|
||||||
|
>Rating <iconify-icon icon="mdi:star" class="text-xl -mb-1"></iconify-icon></label
|
||||||
|
><br />
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
max="5"
|
||||||
|
hidden
|
||||||
|
bind:value={adventure.rating}
|
||||||
|
id="rating"
|
||||||
|
name="rating"
|
||||||
|
class="input input-bordered w-full max-w-xs mt-1"
|
||||||
|
/>
|
||||||
|
<div class="rating -ml-3 mt-1">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="rating-2"
|
||||||
|
class="rating-hidden"
|
||||||
|
checked={Number.isNaN(adventure.rating)}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="rating-2"
|
||||||
|
class="mask mask-star-2 bg-orange-400"
|
||||||
|
on:click={() => (adventure.rating = 1)}
|
||||||
|
checked={adventure.rating === 1}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="rating-2"
|
||||||
|
class="mask mask-star-2 bg-orange-400"
|
||||||
|
on:click={() => (adventure.rating = 2)}
|
||||||
|
checked={adventure.rating === 2}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="rating-2"
|
||||||
|
class="mask mask-star-2 bg-orange-400"
|
||||||
|
on:click={() => (adventure.rating = 3)}
|
||||||
|
checked={adventure.rating === 3}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="rating-2"
|
||||||
|
class="mask mask-star-2 bg-orange-400"
|
||||||
|
on:click={() => (adventure.rating = 4)}
|
||||||
|
checked={adventure.rating === 4}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="rating-2"
|
||||||
|
class="mask mask-star-2 bg-orange-400"
|
||||||
|
on:click={() => (adventure.rating = 5)}
|
||||||
|
checked={adventure.rating === 5}
|
||||||
|
/>
|
||||||
|
{#if adventure.rating}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-sm btn-error ml-2"
|
||||||
|
on:click={() => (adventure.rating = NaN)}
|
||||||
|
>
|
||||||
|
Remove
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div class="mt-2">
|
||||||
|
<div>
|
||||||
|
<label for="is_public"
|
||||||
|
>Public <Earth class="inline-block -mt-1 mb-1 w-6 h-6" /></label
|
||||||
|
><br />
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
class="toggle toggle-primary"
|
||||||
|
id="is_public"
|
||||||
|
name="is_public"
|
||||||
|
bind:checked={adventure.is_public}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="divider"></div>
|
||||||
<div class="divider"></div>
|
<h2 class="text-2xl font-semibold mb-2 mt-2">Location Information</h2>
|
||||||
<h2 class="text-2xl font-semibold mb-2 mt-2">Location Information</h2>
|
<!-- <div class="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3"> -->
|
||||||
<!-- <div class="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3"> -->
|
<div>
|
||||||
<div>
|
<label for="latitude">Location</label><br />
|
||||||
<label for="latitude">Location</label><br />
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
id="location"
|
|
||||||
name="location"
|
|
||||||
bind:value={adventure.location}
|
|
||||||
class="input input-bordered w-full"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<form on:submit={geocode} class="mt-2">
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Seach for a location"
|
id="location"
|
||||||
class="input input-bordered w-full max-w-xs mb-2"
|
name="location"
|
||||||
id="search"
|
bind:value={adventure.location}
|
||||||
name="search"
|
class="input input-bordered w-full"
|
||||||
bind:value={query}
|
|
||||||
/>
|
/>
|
||||||
<button class="btn btn-neutral -mt-1" type="submit">Search</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
{#if places.length > 0}
|
|
||||||
<div class="mt-4 max-w-full">
|
|
||||||
<h3 class="font-bold text-lg mb-4">Search Results</h3>
|
|
||||||
|
|
||||||
<div class="flex flex-wrap">
|
|
||||||
{#each places as place}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="btn btn-neutral mb-2 mr-2 max-w-full break-words whitespace-normal text-left"
|
|
||||||
on:click={() => {
|
|
||||||
markers = [
|
|
||||||
{
|
|
||||||
lngLat: { lng: Number(place.lon), lat: Number(place.lat) },
|
|
||||||
location: place.display_name,
|
|
||||||
name: place.name,
|
|
||||||
activity_type: place.type
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{place.display_name}
|
|
||||||
</button>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{:else if noPlaces}
|
<div>
|
||||||
<p class="text-error text-lg">No results found</p>
|
<form on:submit={geocode} class="mt-2">
|
||||||
{/if}
|
<input
|
||||||
<!-- </div> -->
|
type="text"
|
||||||
<div>
|
placeholder="Seach for a location"
|
||||||
<MapLibre
|
class="input input-bordered w-full max-w-xs mb-2"
|
||||||
style="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
|
id="search"
|
||||||
class="relative aspect-[9/16] max-h-[70vh] w-full sm:aspect-video sm:max-h-full"
|
name="search"
|
||||||
standardControls
|
bind:value={query}
|
||||||
>
|
/>
|
||||||
<!-- MapEvents gives you access to map events even from other components inside the map,
|
<button class="btn btn-neutral -mt-1" type="submit">Search</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{#if places.length > 0}
|
||||||
|
<div class="mt-4 max-w-full">
|
||||||
|
<h3 class="font-bold text-lg mb-4">Search Results</h3>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap">
|
||||||
|
{#each places as place}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-neutral mb-2 mr-2 max-w-full break-words whitespace-normal text-left"
|
||||||
|
on:click={() => {
|
||||||
|
markers = [
|
||||||
|
{
|
||||||
|
lngLat: { lng: Number(place.lon), lat: Number(place.lat) },
|
||||||
|
location: place.display_name,
|
||||||
|
name: place.name,
|
||||||
|
activity_type: place.type,
|
||||||
|
lng: 0
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{place.display_name}
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{:else if noPlaces}
|
||||||
|
<p class="text-error text-lg">No results found</p>
|
||||||
|
{/if}
|
||||||
|
<!-- </div> -->
|
||||||
|
<div>
|
||||||
|
<MapLibre
|
||||||
|
style="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
|
||||||
|
class="relative aspect-[9/16] max-h-[70vh] w-full sm:aspect-video sm:max-h-full"
|
||||||
|
standardControls
|
||||||
|
>
|
||||||
|
<!-- MapEvents gives you access to map events even from other components inside the map,
|
||||||
where you might not have access to the top-level `MapLibre` component. In this case
|
where you might not have access to the top-level `MapLibre` component. In this case
|
||||||
it would also work to just use on:click on the MapLibre component itself. -->
|
it would also work to just use on:click on the MapLibre component itself. -->
|
||||||
<MapEvents on:click={addMarker} />
|
<MapEvents on:click={addMarker} />
|
||||||
|
|
||||||
{#each markers as marker}
|
{#each markers as marker}
|
||||||
<DefaultMarker lngLat={marker.lngLat} />
|
<DefaultMarker lngLat={marker.lngLat} />
|
||||||
{/each}
|
{/each}
|
||||||
</MapLibre>
|
</MapLibre>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mt-4">
|
|
||||||
<button type="submit" class="btn btn-primary">Save & Next</button>
|
|
||||||
<button type="button" class="btn" on:click={close}>Close</button>
|
|
||||||
</div>
|
|
||||||
{#if adventure.is_public}
|
|
||||||
<div class="bg-neutral p-4 mt-2 rounded-md shadow-sm">
|
|
||||||
<p class=" font-semibold">Share this Adventure!</p>
|
|
||||||
<div class="flex items-center justify-between">
|
|
||||||
<p class="text-card-foreground font-mono">
|
|
||||||
{window.location.origin}/adventures/{adventure.id}
|
|
||||||
</p>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
on:click={() => {
|
|
||||||
navigator.clipboard.writeText(
|
|
||||||
`${window.location.origin}/adventures/${adventure.id}`
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
class="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 h-10 px-4 py-2"
|
|
||||||
>
|
|
||||||
Copy Link
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
|
||||||
|
<div class="mt-4">
|
||||||
|
<button type="submit" class="btn btn-primary">Save & Next</button>
|
||||||
|
<button type="button" class="btn" on:click={close}>Close</button>
|
||||||
|
</div>
|
||||||
|
{#if adventure.is_public}
|
||||||
|
<div class="bg-neutral p-4 mt-2 rounded-md shadow-sm">
|
||||||
|
<p class=" font-semibold">Share this Adventure!</p>
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<p class="text-card-foreground font-mono">
|
||||||
|
{window.location.origin}/adventures/{adventure.id}
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
on:click={() => {
|
||||||
|
navigator.clipboard.writeText(
|
||||||
|
`${window.location.origin}/adventures/${adventure.id}`
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
class="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 h-10 px-4 py-2"
|
||||||
|
>
|
||||||
|
Copy Link
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
|
|
|
@ -22,9 +22,6 @@
|
||||||
includeCollections: true
|
includeCollections: true
|
||||||
};
|
};
|
||||||
|
|
||||||
let isShowingCreateModal: boolean = false;
|
|
||||||
let newType: string = '';
|
|
||||||
|
|
||||||
let resultsPerPage: number = 25;
|
let resultsPerPage: number = 25;
|
||||||
|
|
||||||
let count = data.props.count || 0;
|
let count = data.props.count || 0;
|
||||||
|
@ -152,7 +149,6 @@
|
||||||
class="btn btn-primary"
|
class="btn btn-primary"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
isAdventureModalOpen = true;
|
isAdventureModalOpen = true;
|
||||||
newType = 'visited';
|
|
||||||
adventureToEdit = null;
|
adventureToEdit = null;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue