1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-19 12:59:36 +02:00

Wikipedia description fetch

This commit is contained in:
Sean Morley 2024-08-17 22:48:57 -04:00
parent cfe14b3708
commit add2e2bafa
2 changed files with 212 additions and 194 deletions

View file

@ -23,6 +23,8 @@
export let startDate: string | null = null;
export let endDate: string | null = null;
let wikiError: string = '';
let noPlaces: boolean = false;
export let adventureToEdit: Adventure | null = null;
@ -57,7 +59,8 @@
lngLat: { lng: adventure.longitude, lat: adventure.latitude },
location: adventure.location || '',
name: adventure.name,
activity_type: ''
activity_type: '',
lng: 0
}
];
}
@ -210,7 +213,8 @@
lngLat: { lng: longitude, lat: latitude },
location: data[0]?.display_name || '',
name: data[0]?.name || '',
activity_type: data[0]?.type || ''
activity_type: data[0]?.type || '',
lng: 0
}
];
}
@ -240,17 +244,28 @@
}
}
// async function generateDesc() {
// let res = await fetch(`/api/generate/desc/?name=${adventureToEdit.name}`);
// let data = await res.json();
// if (data.extract) {
// adventureToEdit.description = data.extract;
// }
// }
async function generateDesc() {
let res = await fetch(`/api/generate/desc/?name=${adventure.name}`);
let data = await res.json();
if (data.extract?.length > 0) {
adventure.description = data.extract;
} else {
wikiError = 'No description found';
}
}
function addMarker(e: CustomEvent<any>) {
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);
}
@ -393,6 +408,11 @@
bind:value={adventure.description}
class="textarea textarea-bordered w-full h-32"
></textarea>
<div class="mt-2">
<button type="button" class="btn btn-neutral" on:click={generateDesc}
>Generate Description</button
>
<p class="text-red-500">{wikiError}</p>
</div>
<div>
<label for="activity_types">Activity Types</label><br />
@ -530,7 +550,8 @@
lngLat: { lng: Number(place.lon), lat: Number(place.lat) },
location: place.display_name,
name: place.name,
activity_type: place.type
activity_type: place.type,
lng: 0
}
];
}}
@ -586,6 +607,7 @@ it would also work to just use on:click on the MapLibre component itself. -->
</div>
</div>
{/if}
</div>
</form>
</div>
{:else}

View file

@ -22,9 +22,6 @@
includeCollections: true
};
let isShowingCreateModal: boolean = false;
let newType: string = '';
let resultsPerPage: number = 25;
let count = data.props.count || 0;
@ -152,7 +149,6 @@
class="btn btn-primary"
on:click={() => {
isAdventureModalOpen = true;
newType = 'visited';
adventureToEdit = null;
}}
>