mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-05 13:15:18 +02:00
feat: Add validation for adventure name in CreateNewAdventure component
The code changes include adding validation for the adventure name in the CreateNewAdventure component. If the name is empty, an alert is displayed and the adventure creation is prevented. This enhancement ensures that users provide a name for the adventure before creating it.
This commit is contained in:
parent
66d2dc7b15
commit
87cc6da518
2 changed files with 17 additions and 0 deletions
|
@ -26,6 +26,10 @@
|
|||
|
||||
function create() {
|
||||
addActivityType();
|
||||
if (newAdventure.name.trim() === "") {
|
||||
alert("Name is required");
|
||||
return;
|
||||
}
|
||||
dispatch("create", newAdventure);
|
||||
console.log(newAdventure);
|
||||
}
|
||||
|
@ -70,6 +74,7 @@
|
|||
<input
|
||||
type="text"
|
||||
id="name"
|
||||
required
|
||||
bind:value={newAdventure.name}
|
||||
class="input input-bordered w-full max-w-xs"
|
||||
/>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { visitCount } from "$lib/utils/stores/visitCountStore";
|
||||
import type { Adventure } from "$lib/utils/types";
|
||||
|
||||
/**
|
||||
|
@ -111,6 +112,9 @@ export async function addAdventure(
|
|||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
adventureArray.push(data.adventure);
|
||||
if (data.adventure.type === "mylog") {
|
||||
incrementVisitCount(1);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error:", error);
|
||||
|
@ -119,3 +123,11 @@ export async function addAdventure(
|
|||
|
||||
return adventureArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the visit count by the specified amount.
|
||||
* @param {number} amount - The amount to increment the visit count by.
|
||||
*/
|
||||
export function incrementVisitCount(amount: number) {
|
||||
visitCount.update((n) => n + 1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue