Add visit count functionality and update adventure creation
This commit is contained in:
@@ -2,18 +2,27 @@
|
|||||||
export let data;
|
export let data;
|
||||||
console.log(data.result);
|
console.log(data.result);
|
||||||
import AdventureCard from "$lib/components/AdventureCard.svelte";
|
import AdventureCard from "$lib/components/AdventureCard.svelte";
|
||||||
|
import { visitCount } from "$lib/utils/stores/visitCountStore.js";
|
||||||
import type { Adventure } from "$lib/utils/types.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 }>) {
|
function add(event: CustomEvent<{ name: string; location: string }>) {
|
||||||
console.log(event.detail);
|
fetch("/api/visits", {
|
||||||
let newAdventure: Adventure = {
|
method: "POST",
|
||||||
id: getNextId(),
|
headers: {
|
||||||
name: event.detail.name,
|
"Content-Type": "application/json",
|
||||||
location: event.detail.location,
|
},
|
||||||
created: "",
|
body: JSON.stringify({
|
||||||
};
|
name: event.detail.name,
|
||||||
addAdventure(newAdventure);
|
location: event.detail.location,
|
||||||
|
created: "",
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
visitCount.update((n) => n + 1);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user