diff --git a/src/lib/components/AdventureCard.svelte b/src/lib/components/AdventureCard.svelte
index e5bed98..0cdd8a1 100644
--- a/src/lib/components/AdventureCard.svelte
+++ b/src/lib/components/AdventureCard.svelte
@@ -31,6 +31,10 @@
console.log(adventure.id);
goto(`/adventure/${adventure.id}`);
}
+ function markVisited() {
+ console.log(adventure.id);
+ dispatch("markVisited", adventure);
+ }
{/if}
{#if type == "planner"}
+
{
});
}
- const { name, location, date, description, activityTypes, id, rating } =
+ const { name, location, date, description, activityTypes, id, rating, type } =
body.detailAdventure;
if (!name) {
@@ -189,11 +189,18 @@ export async function PUT(event: RequestEvent): Promise {
});
}
+ if (type == "featured") {
+ return error(400, {
+ message: "Featured adventures cannot be created at the moment",
+ });
+ }
+
// update the adventure in the user's visited list
await db
.update(adventureTable)
.set({
name: name,
+ type: type,
location: location,
date: date,
description: description,
diff --git a/src/routes/planner/+page.svelte b/src/routes/planner/+page.svelte
index 8e9092d..409f3d1 100644
--- a/src/routes/planner/+page.svelte
+++ b/src/routes/planner/+page.svelte
@@ -8,6 +8,7 @@
saveAdventure,
removeAdventure,
addAdventure,
+ changeType,
} from "../../services/adventureService.js";
import SucessToast from "$lib/components/SucessToast.svelte";
import mapDrawing from "$lib/assets/adventure_map.svg";
@@ -87,6 +88,18 @@
showToast("Failed to add adventure");
}
};
+
+ async function markVisited(event: { detail: Adventure }) {
+ let initialLength: number = plans.length;
+ let newArray = await changeType(event.detail, "mylog", plans);
+ if (newArray.length + 1 == initialLength) {
+ plans = newArray;
+ showToast("Adventure moved to visit log!");
+ } else {
+ showToast("Failed to moves adventure");
+ }
+ adventureToEdit = undefined;
+ }
{#if isShowingToast}
@@ -131,6 +144,7 @@
type="planner"
on:edit={editPlan}
on:remove={remove}
+ on:markVisited={markVisited}
/>
{/each}
@@ -153,3 +167,52 @@
type="planner"
/>
{/if}
+
+
+
+
+
+
+ My Plans | AdventureLog
+
+
diff --git a/src/services/adventureService.ts b/src/services/adventureService.ts
index 8559702..c8405dc 100644
--- a/src/services/adventureService.ts
+++ b/src/services/adventureService.ts
@@ -124,6 +124,37 @@ export async function addAdventure(
return adventureArray;
}
+export async function changeType(
+ newAdventure: Adventure,
+ newType: string,
+ adventureArray: Adventure[]
+) {
+ newAdventure.type = newType;
+ let detailAdventure = newAdventure;
+
+ const response = await fetch("/api/visits", {
+ method: "PUT",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ detailAdventure }),
+ });
+
+ if (response.ok) {
+ // remove adventure from array where id matches
+ adventureArray = adventureArray.filter(
+ (existingAdventure) => existingAdventure.id !== newAdventure.id
+ );
+ // showToast("Adventure removed successfully!");
+ } else {
+ console.error("Error:", response.statusText);
+ adventureArray = [];
+ }
+
+ console.log(adventureArray);
+
+ return adventureArray;
+}
/**
* Increments the visit count by the specified amount.
* @param {number} amount - The amount to increment the visit count by.