1
0
Fork 0
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:
Sean Morley 2024-05-04 17:27:51 +00:00
parent 66d2dc7b15
commit 87cc6da518
2 changed files with 17 additions and 0 deletions

View file

@ -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"
/>

View file

@ -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);
}