mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-04 04:35:19 +02:00
Add activity types to EditModal component and update server files
This commit is contained in:
parent
6a4771cece
commit
2da4baf8a1
2 changed files with 27 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
</script>
|
||||
|
||||
<dialog id="my_modal_1" class="modal">
|
||||
|
@ -78,6 +94,15 @@
|
|||
class="input input-bordered w-full max-w-xs"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="date">Activity Types</label>
|
||||
<input
|
||||
type="text"
|
||||
id="activityTypes"
|
||||
bind:value={activityInput}
|
||||
class="input input-bordered w-full max-w-xs"
|
||||
/>
|
||||
</div>
|
||||
<button class="btn btn-primary mr-4 mt-4" on:click={submit}>Save</button
|
||||
>
|
||||
<!-- if there is a button in form, it will close the modal -->
|
||||
|
|
|
@ -157,7 +157,7 @@ export async function PUT(event: RequestEvent): Promise<Response> {
|
|||
// 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<Response> {
|
|||
location: location,
|
||||
date: date,
|
||||
description: description,
|
||||
activityTypes: JSON.stringify(activityTypes),
|
||||
})
|
||||
.where(
|
||||
and(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue