diff --git a/src/lib/components/CreateNewAdventure.svelte b/src/lib/components/CreateNewAdventure.svelte index 615b8e4..7dd1639 100644 --- a/src/lib/components/CreateNewAdventure.svelte +++ b/src/lib/components/CreateNewAdventure.svelte @@ -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 @@ diff --git a/src/services/adventureService.ts b/src/services/adventureService.ts index b39492d..8559702 100644 --- a/src/services/adventureService.ts +++ b/src/services/adventureService.ts @@ -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); +}