From 8888650c564261921035895255d8fe96da347818 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Sun, 26 May 2024 20:07:23 +0000 Subject: [PATCH] Add more options for featured adventures --- src/lib/components/AddFromFeatured.svelte | 50 +++++++++++++++++++ src/lib/db/schema.ts | 6 --- src/routes/featured/+page.server.ts | 2 +- src/routes/featured/+page.svelte | 61 ++++++++++++++++++++++- 4 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 src/lib/components/AddFromFeatured.svelte diff --git a/src/lib/components/AddFromFeatured.svelte b/src/lib/components/AddFromFeatured.svelte new file mode 100644 index 0000000..702a10a --- /dev/null +++ b/src/lib/components/AddFromFeatured.svelte @@ -0,0 +1,50 @@ + + + + + + + diff --git a/src/lib/db/schema.ts b/src/lib/db/schema.ts index 5cb928b..a6298a8 100644 --- a/src/lib/db/schema.ts +++ b/src/lib/db/schema.ts @@ -9,12 +9,6 @@ import { integer, } from "drizzle-orm/pg-core"; -export const featuredAdventures = pgTable("featuredAdventures", { - id: serial("id").primaryKey(), - name: text("name").notNull().unique(), - location: text("location"), -}); - export const sharedAdventures = pgTable("sharedAdventures", { id: text("id").primaryKey(), data: json("data").notNull(), diff --git a/src/routes/featured/+page.server.ts b/src/routes/featured/+page.server.ts index c60aa47..50b0180 100644 --- a/src/routes/featured/+page.server.ts +++ b/src/routes/featured/+page.server.ts @@ -1,5 +1,5 @@ import { db } from "$lib/db/db.server"; -import { adventureTable, featuredAdventures } from "$lib/db/schema"; +import { adventureTable } from "$lib/db/schema"; import type { Adventure } from "$lib/utils/types"; import { eq } from "drizzle-orm"; diff --git a/src/routes/featured/+page.svelte b/src/routes/featured/+page.svelte index 1f6c57c..0a0745d 100644 --- a/src/routes/featured/+page.svelte +++ b/src/routes/featured/+page.svelte @@ -3,9 +3,32 @@ import { goto } from "$app/navigation"; import AdventureCard from "$lib/components/AdventureCard.svelte"; import type { Adventure } from "$lib/utils/types.js"; + import AddFromFeatured from "$lib/components/AddFromFeatured.svelte"; + import { addAdventure } from "../../services/adventureService.js"; + import SucessToast from "$lib/components/SucessToast.svelte"; + + let isShowingToast: boolean = false; + let toastAction: string = ""; + + let adventureToAdd: Adventure | null = null; + + function showToast(action: string) { + toastAction = action; + isShowingToast = true; + + setTimeout(() => { + isShowingToast = false; + toastAction = ""; + }, 3000); + } async function add(event: CustomEvent) { - let detailAdventure = event.detail; + adventureToAdd = event.detail; + } + + async function addToVisted() { + let detailAdventure = adventureToAdd; + adventureToAdd = null; const response = await fetch("/api/visits", { method: "POST", @@ -19,10 +42,46 @@ if (response.status === 401) { goto("/login"); + } else { + showToast("Adventure added to visited list!"); + } + } + + async function addIdea() { + let detailAdventure = adventureToAdd; + adventureToAdd = null; + + const response = await fetch("/api/planner", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + detailAdventure, + }), + }); + + if (response.status === 401) { + goto("/login"); + } else { + showToast("Adventure added to idea list!"); } } +{#if isShowingToast} + +{/if} + +{#if adventureToAdd} + (adventureToAdd = null)} + on:visited={addToVisted} + on:idea={addIdea} + /> +{/if} +

Featured Adventure Locations