diff --git a/src/lib/components/AdventureCard.svelte b/src/lib/components/AdventureCard.svelte
index ceaf5e4..7ae6205 100644
--- a/src/lib/components/AdventureCard.svelte
+++ b/src/lib/components/AdventureCard.svelte
@@ -109,6 +109,10 @@
> -->
+
{
@@ -46,6 +46,28 @@
}
}
+ async function generate() {
+ try {
+ console.log(newAdventure.name);
+ const desc = await generateDescription(newAdventure.name);
+ newAdventure.description = desc;
+ // Do something with the updated newAdventure object
+ } catch (error) {
+ console.error(error);
+ // Handle the error
+ }
+ }
+
+ async function searchImage() {
+ try {
+ const imageUrl = await getImage(newAdventure.name);
+ newAdventure.imageUrl = imageUrl;
+ } catch (error) {
+ console.error(error);
+ // Handle the error
+ }
+ }
+
let activityInput: string = "";
function activitySetup() {
@@ -102,6 +124,7 @@
class="input input-bordered w-full max-w-xs"
/>
+
+
+
diff --git a/src/lib/components/TripCard.svelte b/src/lib/components/TripCard.svelte
index 2c291e2..a7fc61b 100644
--- a/src/lib/components/TripCard.svelte
+++ b/src/lib/components/TripCard.svelte
@@ -19,11 +19,7 @@
dispatch("add", trip);
}
- function moreInfo() {
- console.log(trip.id);
- goto(`/trip/${trip.id}`);
- }
-
+ // TODO: Implement markVisited function
function markVisited() {
console.log(trip.id);
dispatch("markVisited", trip);
diff --git a/src/lib/index.ts b/src/lib/index.ts
index 07c1c49..078bef0 100644
--- a/src/lib/index.ts
+++ b/src/lib/index.ts
@@ -63,3 +63,64 @@ export function addActivityType(
}
return adventureToEdit;
}
+
+/**
+ * Generates a description for an adventure using the adventure title.
+ * @param adventureTitle - The title of the adventure.
+ * @returns A Promise that resolves to the description of the adventure.
+ */
+export async function generateDescription(adventureTitle: string) {
+ const url = `https://en.wikipedia.org/w/api.php?origin=*&action=query&prop=extracts&exintro&explaintext&format=json&titles=${encodeURIComponent(
+ adventureTitle
+ )}`;
+
+ try {
+ const res = await fetch(url);
+ const data = await res.json();
+
+ // Check if the query was successful
+ if (data.query && data.query.pages) {
+ const pageId = Object.keys(data.query.pages)[0];
+ const page = data.query.pages[pageId];
+
+ // Check if the page exists
+ if (page.extract) {
+ return page.extract;
+ } else {
+ return `No Wikipedia article found for "${adventureTitle}".`;
+ }
+ } else {
+ return `Error: ${data.error.info}`;
+ }
+ } catch (error) {
+ console.error("Error fetching Wikipedia data:", error);
+ return `Error fetching Wikipedia data for "${adventureTitle}".`;
+ }
+}
+
+export async function getImage(adventureTitle: string) {
+ const url = `https://en.wikipedia.org/w/api.php?origin=*&action=query&prop=pageimages&format=json&piprop=original&titles=${adventureTitle}`;
+
+ try {
+ const res = await fetch(url);
+ const data = await res.json();
+
+ // Check if the query was successful
+ if (data.query && data.query.pages) {
+ const pageId = Object.keys(data.query.pages)[0];
+ const page = data.query.pages[pageId];
+
+ // Check if the page has an image
+ if (page.original && page.original.source) {
+ return page.original.source;
+ } else {
+ return `No image found for "${adventureTitle}".`;
+ }
+ } else {
+ return `Error: ${data.error.info}`;
+ }
+ } catch (error) {
+ console.error("Error fetching Wikipedia data:", error);
+ return `Error fetching Wikipedia data for "${adventureTitle}".`;
+ }
+}
diff --git a/src/routes/planner/+page.svelte b/src/routes/planner/+page.svelte
index 9ee26a2..4377748 100644
--- a/src/routes/planner/+page.svelte
+++ b/src/routes/planner/+page.svelte
@@ -271,7 +271,7 @@
{#if tripPlans.length !== 0}
- My Trip Plans
+ My Trip Ideas
{/if}