From 82eb6c2f973b285373f7aa684b6962424d993013 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Tue, 4 Jun 2024 21:22:33 +0000 Subject: [PATCH] fix null search errors --- src/routes/search/+page.svelte | 57 +++++++++++----------------------- 1 file changed, 18 insertions(+), 39 deletions(-) diff --git a/src/routes/search/+page.svelte b/src/routes/search/+page.svelte index 0cd41db..f3601d3 100644 --- a/src/routes/search/+page.svelte +++ b/src/routes/search/+page.svelte @@ -5,29 +5,31 @@ import type { SubmitFunction } from "@sveltejs/kit"; import type { PageData } from "./$types"; - let visitedValue = "all"; - let typeValue = ""; + // let visitedValue = "all"; + // let typeValue = ""; export let data: PageData; let adventureArray: Adventure[] = data.props?.adventures as Adventure[]; const filter: SubmitFunction = async ({ formData }) => { - visitedValue = formData.get("visited") as string; - typeValue = formData.get("type") as string; + const radioValue = formData.get("visited") as string; + let typeValue = formData.get("type") as string; + if (!typeValue) { + typeValue = ""; + } const value = new URLSearchParams(location.search).get("value"); - + console.log(value); console.log( - `/api/search?value=${value}&type=${typeValue}&visited=${visitedValue}` + `/api/search?value=${value}&type=${typeValue}&visited=${radioValue}` ); - - let response = await fetch( - `/api/search?value=${value}&type=${typeValue}&visited=${visitedValue}` + let data = await fetch( + `/api/search?value=${value}&type=${typeValue}&visited=${radioValue}` ); - console.log(response); - - let res = await response.json(); + console.log(data); + adventureArray = []; + let res = await data.json(); adventureArray = res.adventures as Adventure[]; - console.log("TEST" + visitedValue + " " + typeValue); + console.log(radioValue); }; @@ -37,46 +39,32 @@ type="radio" name="visited" value="all" + checked class="radio radio-primary" - bind:group={visitedValue} - checked={visitedValue === "all"} /> All Not Visited Visited
- + All Activity Location - + Name