boredgame/src/lib/components/search/textSearch/index.svelte

67 lines
1.6 KiB
Svelte
Raw Normal View History

<script lang="ts">
import { boredState } from '$lib/stores/boredState';
import { gameStore } from '$lib/stores/gameSearchStore';
async function handleSearch(event: SubmitEvent) {
boredState.set({ loading: true });
const form = event.target as HTMLFormElement;
console.log('form', form);
const response = await fetch('/api/game', {
method: 'POST',
headers: { accept: 'application/json' },
body: new FormData(form)
});
const responseData = await response.json();
boredState.set({ loading: false });
gameStore.removeAll();
gameStore.addAll(responseData?.games);
}
export let showButton: boolean = false;
export let advancedSearch: boolean = false;
console.log('showButton', showButton);
2022-07-29 00:07:23 +00:00
let submitting = $boredState?.loading;
let name = '';
</script>
<form on:submit|preventDefault={handleSearch} method="post">
<fieldset aria-busy={submitting} disabled={submitting}>
2022-07-29 00:07:23 +00:00
<label for="name">
Search
<input
id="name"
name="name"
bind:value={name}
type="text"
aria-label="Search boardgame"
placeholder="Search boardgame"
/>
{#if showButton}
<button class="btn" type="submit" disabled={submitting}>Search</button>
{/if}
</label>
</fieldset>
</form>
<style lang="scss">
2022-07-29 00:07:23 +00:00
form {
display: grid;
place-items: start;
}
h1 {
width: 100%;
}
button {
padding: 1rem;
}
label {
display: grid;
2022-07-29 00:07:23 +00:00
grid-template-columns: auto auto auto;
gap: 1rem;
place-items: center;
margin: 1rem;
}
</style>