mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-04 12:45:17 +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) {
|
if (modal) {
|
||||||
modal.showModal();
|
modal.showModal();
|
||||||
}
|
}
|
||||||
|
activityInput = (adventureToEdit?.activityTypes || []).join(", ");
|
||||||
});
|
});
|
||||||
|
|
||||||
function submit() {
|
function submit() {
|
||||||
|
addActivityType();
|
||||||
dispatch("submit", adventureToEdit);
|
dispatch("submit", adventureToEdit);
|
||||||
console.log(adventureToEdit);
|
console.log(adventureToEdit);
|
||||||
}
|
}
|
||||||
|
@ -29,6 +31,20 @@
|
||||||
close();
|
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>
|
</script>
|
||||||
|
|
||||||
<dialog id="my_modal_1" class="modal">
|
<dialog id="my_modal_1" class="modal">
|
||||||
|
@ -78,6 +94,15 @@
|
||||||
class="input input-bordered w-full max-w-xs"
|
class="input input-bordered w-full max-w-xs"
|
||||||
/>
|
/>
|
||||||
</div>
|
</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
|
<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 -->
|
<!-- 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
|
// get properties from the body
|
||||||
const { newAdventure } = await event.request.json();
|
const { newAdventure } = await event.request.json();
|
||||||
console.log(newAdventure);
|
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
|
// update the adventure in the user's visited list
|
||||||
await db
|
await db
|
||||||
|
@ -167,6 +167,7 @@ export async function PUT(event: RequestEvent): Promise<Response> {
|
||||||
location: location,
|
location: location,
|
||||||
date: date,
|
date: date,
|
||||||
description: description,
|
description: description,
|
||||||
|
activityTypes: JSON.stringify(activityTypes),
|
||||||
})
|
})
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue