Add POST endpoint to create new adventure and update adventureService

This commit is contained in:
Sean Morley
2024-04-10 14:51:51 +00:00
parent 7ba879f7d9
commit ed9a579fc2
3 changed files with 88 additions and 30 deletions

View File

@@ -7,13 +7,7 @@ import { visitCount } from "$lib/utils/stores/visitCountStore";
// Check if localStorage is available (browser environment)
const isBrowser = typeof window !== "undefined";
// // Load adventures from localStorage on startup (only in the browser)
// if (isBrowser) {
// const storedAdventures = localStorage.getItem("adventures");
// if (storedAdventures) {
// adventures = JSON.parse(storedAdventures);
// }
// }
//
export function getNextId() {
let nextId = Math.max(0, ...adventures.map((adventure) => adventure.id)) + 1;
@@ -37,14 +31,6 @@ export function getAdventures(): Adventure[] {
return adventures;
}
export function removeAdventure(event: { detail: number }) {
adventures = adventures.filter((adventure) => adventure.id !== event.detail);
if (isBrowser) {
localStorage.setItem("adventures", JSON.stringify(adventures));
visitCount.update((n) => n - 1);
}
}
export function saveEdit(adventure: Adventure) {
let editId = adventure.id;
console.log("saving edit");