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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user