2022-07-25 20:22:24 +00:00
|
|
|
<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);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-03 05:37:21 +00:00
|
|
|
export let showButton: boolean = false;
|
|
|
|
|
export let advancedSearch: boolean = false;
|
|
|
|
|
console.log('showButton', showButton);
|
2022-07-29 00:07:23 +00:00
|
|
|
|
2022-07-25 20:22:24 +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>
|
2022-07-25 20:22:24 +00:00
|
|
|
</fieldset>
|
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
2022-07-29 00:07:23 +00:00
|
|
|
form {
|
|
|
|
|
display: grid;
|
|
|
|
|
place-items: start;
|
|
|
|
|
}
|
2022-07-25 20:22:24 +00:00
|
|
|
h1 {
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
button {
|
2022-08-03 05:37:21 +00:00
|
|
|
padding: 1rem;
|
2022-07-25 20:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
label {
|
|
|
|
|
display: grid;
|
2022-07-29 00:07:23 +00:00
|
|
|
grid-template-columns: auto auto auto;
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
place-items: center;
|
2022-07-25 20:22:24 +00:00
|
|
|
margin: 1rem;
|
|
|
|
|
}
|
|
|
|
|
</style>
|