From 2da4baf8a10e61bcea5c76a825145c22fc9eff3d Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Wed, 1 May 2024 00:14:31 +0000 Subject: [PATCH] Add activity types to EditModal component and update server files --- src/lib/components/EditModal.svelte | 25 +++++++++++++++++++++++++ src/routes/api/visits/+server.ts | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/lib/components/EditModal.svelte b/src/lib/components/EditModal.svelte index 5b1db35..11e7814 100644 --- a/src/lib/components/EditModal.svelte +++ b/src/lib/components/EditModal.svelte @@ -13,9 +13,11 @@ if (modal) { modal.showModal(); } + activityInput = (adventureToEdit?.activityTypes || []).join(", "); }); function submit() { + addActivityType(); dispatch("submit", adventureToEdit); console.log(adventureToEdit); } @@ -29,6 +31,20 @@ close(); } } + + let activityInput: string = ""; + + function addActivityType() { + if (activityInput.trim() !== "") { + const activities = activityInput + .split(",") + .map((activity) => activity.trim()); + adventureToEdit.activityTypes = activities; + // override the original activity types + activityInput = ""; + } + console.log(adventureToEdit.activityTypes); + } @@ -78,6 +94,15 @@ class="input input-bordered w-full max-w-xs" /> +
+ + +
diff --git a/src/routes/api/visits/+server.ts b/src/routes/api/visits/+server.ts index dedf2b2..37cf393 100644 --- a/src/routes/api/visits/+server.ts +++ b/src/routes/api/visits/+server.ts @@ -157,7 +157,7 @@ export async function PUT(event: RequestEvent): Promise { // get properties from the body const { newAdventure } = await event.request.json(); console.log(newAdventure); - const { name, location, date, id, description } = newAdventure; + const { name, location, date, id, description, activityTypes } = newAdventure; // update the adventure in the user's visited list await db @@ -167,6 +167,7 @@ export async function PUT(event: RequestEvent): Promise { location: location, date: date, description: description, + activityTypes: JSON.stringify(activityTypes), }) .where( and(