mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-07 06:05:19 +02:00
feat: Add activity types functionality to CreateNewAdventure and AdventureCard components
This commit is contained in:
parent
eab7cb6087
commit
3127784632
4 changed files with 38 additions and 17 deletions
|
@ -46,10 +46,7 @@
|
||||||
const activities = activityInput
|
const activities = activityInput
|
||||||
.split(" ")
|
.split(" ")
|
||||||
.filter((activity) => activity.trim() !== "");
|
.filter((activity) => activity.trim() !== "");
|
||||||
newAdventure.activityTypes = [
|
newAdventure.activityTypes = activities;
|
||||||
...(newAdventure.activityTypes || []),
|
|
||||||
...activities,
|
|
||||||
];
|
|
||||||
activityInput = "";
|
activityInput = "";
|
||||||
}
|
}
|
||||||
console.log(newAdventure.activityTypes);
|
console.log(newAdventure.activityTypes);
|
||||||
|
@ -104,7 +101,7 @@
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="date">Activity Types</label>
|
<label for="date">Activity Types (Comma Seperated)</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
id="activityTypes"
|
id="activityTypes"
|
||||||
|
@ -112,6 +109,17 @@
|
||||||
class="input input-bordered w-full max-w-xs"
|
class="input input-bordered w-full max-w-xs"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="rating">Rating</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
max="5"
|
||||||
|
id="rating"
|
||||||
|
bind:value={newAdventure.rating}
|
||||||
|
class="input input-bordered w-full max-w-xs"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
class="btn btn-primary mr-4 mt-4"
|
class="btn btn-primary mr-4 mt-4"
|
||||||
|
|
|
@ -40,9 +40,8 @@
|
||||||
if (activityInput.trim() !== "") {
|
if (activityInput.trim() !== "") {
|
||||||
const activities = activityInput
|
const activities = activityInput
|
||||||
.split(",")
|
.split(",")
|
||||||
.map((activity) => activity.trim());
|
.filter((activity) => activity.trim() !== "");
|
||||||
adventureToEdit.activityTypes = activities;
|
adventureToEdit.activityTypes = activities;
|
||||||
// override the original activity types
|
|
||||||
activityInput = "";
|
activityInput = "";
|
||||||
}
|
}
|
||||||
console.log(adventureToEdit.activityTypes);
|
console.log(adventureToEdit.activityTypes);
|
||||||
|
@ -97,7 +96,7 @@
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="date">Activity Types</label>
|
<label for="date">Activity Types (Comma Seperated)</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
id="activityTypes"
|
id="activityTypes"
|
||||||
|
@ -105,6 +104,17 @@
|
||||||
class="input input-bordered w-full max-w-xs"
|
class="input input-bordered w-full max-w-xs"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="rating">Rating</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
max="5"
|
||||||
|
id="rating"
|
||||||
|
bind:value={adventureToEdit.rating}
|
||||||
|
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 -->
|
||||||
|
|
|
@ -103,7 +103,7 @@ export async function POST(event: RequestEvent): Promise<Response> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const { name, location, date, description, activityTypes } =
|
const { name, location, date, description, activityTypes, rating } =
|
||||||
body.detailAdventure;
|
body.detailAdventure;
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
|
@ -112,6 +112,12 @@ export async function POST(event: RequestEvent): Promise<Response> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rating && (rating < 1 || rating > 5)) {
|
||||||
|
return error(400, {
|
||||||
|
message: "Rating must be between 1 and 5",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
console.log(activityTypes);
|
console.log(activityTypes);
|
||||||
|
|
||||||
// insert the adventure to the user's visited list
|
// insert the adventure to the user's visited list
|
||||||
|
@ -125,6 +131,7 @@ export async function POST(event: RequestEvent): Promise<Response> {
|
||||||
date: date || null,
|
date: date || null,
|
||||||
description: description || null,
|
description: description || null,
|
||||||
activityTypes: JSON.stringify(activityTypes) || null,
|
activityTypes: JSON.stringify(activityTypes) || null,
|
||||||
|
rating: rating || null,
|
||||||
})
|
})
|
||||||
.returning({ insertedId: adventureTable.id })
|
.returning({ insertedId: adventureTable.id })
|
||||||
.execute();
|
.execute();
|
||||||
|
@ -168,7 +175,7 @@ export async function PUT(event: RequestEvent): Promise<Response> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const { name, location, date, description, activityTypes, id } =
|
const { name, location, date, description, activityTypes, id, rating } =
|
||||||
body.detailAdventure;
|
body.detailAdventure;
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
|
@ -185,6 +192,7 @@ export async function PUT(event: RequestEvent): Promise<Response> {
|
||||||
location: location,
|
location: location,
|
||||||
date: date,
|
date: date,
|
||||||
description: description,
|
description: description,
|
||||||
|
rating: rating,
|
||||||
activityTypes: JSON.stringify(activityTypes),
|
activityTypes: JSON.stringify(activityTypes),
|
||||||
})
|
})
|
||||||
.where(
|
.where(
|
||||||
|
|
|
@ -11,12 +11,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
async function add(event: CustomEvent<Adventure>) {
|
async function add(event: CustomEvent<Adventure>) {
|
||||||
let newAdventure: Adventure = {
|
let detailAdventure = event.detail;
|
||||||
name: event.detail.name,
|
|
||||||
location: event.detail.location,
|
|
||||||
type: "mylog",
|
|
||||||
id: -1,
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await fetch("/api/visits", {
|
const response = await fetch("/api/visits", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -24,7 +19,7 @@
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
newAdventure,
|
detailAdventure,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue