1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-08-02 19:55:18 +02:00

Add visit count functionality and update adventure creation

This commit is contained in:
Sean Morley 2024-04-10 18:00:24 +00:00
parent 3dcad53004
commit 818ab5239d

View file

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