From 818ab5239d39442b4f81d6c0eb5d661b3e617896 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Wed, 10 Apr 2024 18:00:24 +0000 Subject: [PATCH] Add visit count functionality and update adventure creation --- src/routes/featured/+page.svelte | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/routes/featured/+page.svelte b/src/routes/featured/+page.svelte index 93f0ad0..947840c 100644 --- a/src/routes/featured/+page.svelte +++ b/src/routes/featured/+page.svelte @@ -2,18 +2,27 @@ export let data; console.log(data.result); import AdventureCard from "$lib/components/AdventureCard.svelte"; + import { visitCount } from "$lib/utils/stores/visitCountStore.js"; import type { Adventure } from "$lib/utils/types.js"; - import { addAdventure, getNextId } from "../../services/adventureService.js"; + + let count = 0; + visitCount.subscribe((value) => { + count = value; + }); function add(event: CustomEvent<{ name: string; location: string }>) { - console.log(event.detail); - let newAdventure: Adventure = { - id: getNextId(), - name: event.detail.name, - location: event.detail.location, - created: "", - }; - addAdventure(newAdventure); + fetch("/api/visits", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: event.detail.name, + location: event.detail.location, + created: "", + }), + }); + visitCount.update((n) => n + 1); }