1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-08-03 20:25:18 +02:00

feat: Add search functionality to navbar

This commit is contained in:
Sean Morley 2024-06-04 21:18:30 +00:00
parent 18b4dfa922
commit eadf001b39
2 changed files with 23 additions and 13 deletions

View file

@ -100,9 +100,12 @@
<li> <li>
<label class="input input-bordered flex items-center gap-2"> <label class="input input-bordered flex items-center gap-2">
<input type="text" class="grow" placeholder="Search" /> <input type="text" class="grow" placeholder="Search" />
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16" viewBox="0 0 16 16"
on:click={() => goToSearch()}
fill="currentColor" fill="currentColor"
class="w-4 h-4 opacity-70" class="w-4 h-4 opacity-70"
><path ><path

View file

@ -12,21 +12,22 @@
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 }) => {
const radioValue = formData.get("visited"); visitedValue = formData.get("visited") as string;
const typeValue = formData.get("type"); typeValue = formData.get("type") as string;
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=${radioValue}` `/api/search?value=${value}&type=${typeValue}&visited=${visitedValue}`
); );
let data = await fetch(
`/api/search?value=${value}&type=${typeValue}&visited=${radioValue}` let response = await fetch(
`/api/search?value=${value}&type=${typeValue}&visited=${visitedValue}`
); );
console.log(data); console.log(response);
adventureArray = [];
let res = await data.json(); let res = await response.json();
adventureArray = res.adventures as Adventure[]; adventureArray = res.adventures as Adventure[];
console.log(radioValue); console.log("TEST" + visitedValue + " " + typeValue);
}; };
</script> </script>
@ -38,7 +39,7 @@
value="all" value="all"
class="radio radio-primary" class="radio radio-primary"
bind:group={visitedValue} bind:group={visitedValue}
checked checked={visitedValue === "all"}
/> />
All All
<input <input
@ -47,6 +48,7 @@
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
@ -55,6 +57,7 @@
name="visited" name="visited"
value="true" value="true"
class="radio radio-primary" class="radio radio-primary"
checked={visitedValue === "true"}
/> />
Visited Visited
<br /> <br />
@ -64,6 +67,7 @@
value="" value=""
class="radio radio-primary" class="radio radio-primary"
bind:group={typeValue} bind:group={typeValue}
checked={typeValue === ""}
/> />
All All
<input <input
@ -72,22 +76,25 @@
value="activity" value="activity"
class="radio radio-primary" class="radio radio-primary"
bind:group={typeValue} bind:group={typeValue}
checked={typeValue === "activity"}
/> />
Activity Activity
<input <input
type="radio" type="radio"
name="type" name="type"
bind:group={typeValue}
value="location" value="location"
class="radio radio-primary" class="radio radio-primary"
bind:group={typeValue}
checked={typeValue === "location"}
/> />
Location Location
<input <input
type="radio" type="radio"
bind:group={typeValue}
name="type" name="type"
value="name" value="name"
class="radio radio-primary" class="radio radio-primary"
bind:group={typeValue}
checked={typeValue === "name"}
/> />
Name Name
<!-- submit button --> <!-- submit button -->