1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-08-05 05:05:17 +02:00

fix null search errors

This commit is contained in:
Sean Morley 2024-06-04 21:22:33 +00:00
parent eadf001b39
commit 82eb6c2f97

View file

@ -5,29 +5,31 @@
import type { SubmitFunction } from "@sveltejs/kit"; import type { SubmitFunction } from "@sveltejs/kit";
import type { PageData } from "./$types"; import type { PageData } from "./$types";
let visitedValue = "all"; // let visitedValue = "all";
let typeValue = ""; // let typeValue = "";
export let data: PageData; export let data: PageData;
let adventureArray: Adventure[] = data.props?.adventures as Adventure[]; let adventureArray: Adventure[] = data.props?.adventures as Adventure[];
const filter: SubmitFunction = async ({ formData }) => { const filter: SubmitFunction = async ({ formData }) => {
visitedValue = formData.get("visited") as string; const radioValue = formData.get("visited") as string;
typeValue = formData.get("type") as string; let typeValue = formData.get("type") as string;
if (!typeValue) {
typeValue = "";
}
const value = new URLSearchParams(location.search).get("value"); const value = new URLSearchParams(location.search).get("value");
console.log(value);
console.log( console.log(
`/api/search?value=${value}&type=${typeValue}&visited=${visitedValue}` `/api/search?value=${value}&type=${typeValue}&visited=${radioValue}`
); );
let data = await fetch(
let response = await fetch( `/api/search?value=${value}&type=${typeValue}&visited=${radioValue}`
`/api/search?value=${value}&type=${typeValue}&visited=${visitedValue}`
); );
console.log(response); console.log(data);
adventureArray = [];
let res = await response.json(); let res = await data.json();
adventureArray = res.adventures as Adventure[]; adventureArray = res.adventures as Adventure[];
console.log("TEST" + visitedValue + " " + typeValue); console.log(radioValue);
}; };
</script> </script>
@ -37,46 +39,32 @@
type="radio" type="radio"
name="visited" name="visited"
value="all" value="all"
checked
class="radio radio-primary" class="radio radio-primary"
bind:group={visitedValue}
checked={visitedValue === "all"}
/> />
All All
<input <input
type="radio" type="radio"
bind:group={visitedValue}
name="visited" name="visited"
value="false" value="false"
class="radio radio-primary" class="radio radio-primary"
checked={visitedValue === "false"}
/> />
Not Visited Not Visited
<input <input
type="radio" type="radio"
bind:group={visitedValue}
name="visited" name="visited"
value="true" value="true"
class="radio radio-primary" class="radio radio-primary"
checked={visitedValue === "true"}
/> />
Visited Visited
<br /> <br />
<input <input type="radio" name="type" value="" class="radio radio-primary" />
type="radio"
name="type"
value=""
class="radio radio-primary"
bind:group={typeValue}
checked={typeValue === ""}
/>
All All
<input <input
type="radio" type="radio"
name="type" name="type"
value="activity" value="activity"
class="radio radio-primary" class="radio radio-primary"
bind:group={typeValue}
checked={typeValue === "activity"}
/> />
Activity Activity
<input <input
@ -84,18 +72,9 @@
name="type" name="type"
value="location" value="location"
class="radio radio-primary" class="radio radio-primary"
bind:group={typeValue}
checked={typeValue === "location"}
/> />
Location Location
<input <input type="radio" name="type" value="name" class="radio radio-primary" />
type="radio"
name="type"
value="name"
class="radio radio-primary"
bind:group={typeValue}
checked={typeValue === "name"}
/>
Name Name
<!-- submit button --> <!-- submit button -->
<button type="submit" class="btn btn-primary">Search</button> <button type="submit" class="btn btn-primary">Search</button>