mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-04 04:35:19 +02:00
Add visit count functionality and update adventure creation
This commit is contained in:
parent
3dcad53004
commit
818ab5239d
1 changed files with 18 additions and 9 deletions
|
@ -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>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue