2022-01-28 05:27:12 +00:00
|
|
|
<script lang="ts">
|
2022-09-01 02:32:30 +00:00
|
|
|
import type { GameType, SavedGameType } from '$root/lib/types';
|
|
|
|
|
import { gameStore } from '$lib/stores/gameSearchStore';
|
|
|
|
|
import { boredState } from '$root/lib/stores/boredState';
|
|
|
|
|
import RemoveCollectionDialog from '$root/lib/components/dialog/RemoveCollectionDialog.svelte';
|
2022-07-12 00:00:32 +00:00
|
|
|
import Game from '$lib/components/game/index.svelte';
|
2022-07-25 20:22:24 +00:00
|
|
|
import TextSearch from '$lib/components/search/textSearch/index.svelte';
|
|
|
|
|
import RandomSearch from '$lib/components/search/random/index.svelte';
|
2022-07-27 00:23:58 +00:00
|
|
|
import Random from '$lib/components/random/index.svelte';
|
2022-08-07 21:53:21 +00:00
|
|
|
|
|
|
|
|
async function handleSearch(event: SubmitEvent) {
|
2022-08-31 20:47:03 +00:00
|
|
|
boredState.update((n) => ({ ...n, loading: true }));
|
2022-08-07 21:53:21 +00:00
|
|
|
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();
|
2022-08-31 20:47:03 +00:00
|
|
|
boredState.update((n) => ({ ...n, loading: false }));
|
2022-08-07 21:53:21 +00:00
|
|
|
gameStore.removeAll();
|
|
|
|
|
gameStore.addAll(responseData?.games);
|
|
|
|
|
}
|
2022-08-31 04:15:31 +00:00
|
|
|
|
|
|
|
|
let isOpen: boolean = false;
|
|
|
|
|
let gameToRemove: GameType | SavedGameType;
|
|
|
|
|
console.log('isOpen', isOpen);
|
|
|
|
|
|
|
|
|
|
interface RemoveGameEvent extends Event {
|
|
|
|
|
detail: GameType | SavedGameType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleRemoveGame(event: RemoveGameEvent) {
|
|
|
|
|
console.log('event', event);
|
|
|
|
|
gameToRemove = event?.detail;
|
2022-09-01 02:32:30 +00:00
|
|
|
boredState.update((n) => ({
|
|
|
|
|
...n,
|
|
|
|
|
dialog: { isOpen: true, content: RemoveCollectionDialog, additionalData: gameToRemove }
|
|
|
|
|
}));
|
2022-08-31 04:15:31 +00:00
|
|
|
}
|
2022-01-28 05:27:12 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<svelte:head>
|
2022-09-01 02:32:30 +00:00
|
|
|
<title>Bored Game | Home</title>
|
2022-01-28 05:27:12 +00:00
|
|
|
</svelte:head>
|
|
|
|
|
|
2022-04-24 23:38:12 +00:00
|
|
|
<h1>Search Boardgames!</h1>
|
|
|
|
|
<p>Input your requirements to search for board game that match your criteria</p>
|
2022-07-27 22:05:22 +00:00
|
|
|
<div class="game-search">
|
2022-08-07 21:53:21 +00:00
|
|
|
<form on:submit|preventDefault={handleSearch} method="post">
|
|
|
|
|
<TextSearch showButton advancedSearch />
|
|
|
|
|
</form>
|
2022-07-27 22:05:22 +00:00
|
|
|
<div class="random-buttons">
|
|
|
|
|
<RandomSearch />
|
|
|
|
|
<Random />
|
|
|
|
|
</div>
|
2022-04-24 23:38:12 +00:00
|
|
|
</div>
|
|
|
|
|
|
2022-08-31 04:15:31 +00:00
|
|
|
{#if $gameStore?.length > 0}
|
|
|
|
|
<div class="games">
|
|
|
|
|
<h1>Games Found:</h1>
|
|
|
|
|
<div class="games-list">
|
|
|
|
|
{#each $gameStore as game}
|
|
|
|
|
<Game on:removeGameEvent={handleRemoveGame} {game} />
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
2022-08-02 06:26:57 +00:00
|
|
|
</div>
|
2022-08-31 04:15:31 +00:00
|
|
|
{/if}
|
2022-04-24 23:38:12 +00:00
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
.games {
|
2022-08-09 23:19:37 +00:00
|
|
|
margin: 2rem 0rem;
|
|
|
|
|
|
|
|
|
|
h1 {
|
|
|
|
|
margin-bottom: 2rem;
|
|
|
|
|
}
|
2022-08-02 06:26:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.games-list {
|
2022-07-10 19:51:44 +00:00
|
|
|
display: grid;
|
2022-08-09 23:19:37 +00:00
|
|
|
grid-template-columns: repeat(3, minmax(200px, 1fr));
|
2022-04-24 23:38:12 +00:00
|
|
|
gap: 2rem;
|
2022-07-10 19:55:30 +00:00
|
|
|
|
2022-07-11 04:17:59 +00:00
|
|
|
@media (max-width: 800px) {
|
|
|
|
|
grid-template-columns: 1fr 1fr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-07 22:02:14 +00:00
|
|
|
@media (max-width: 650px) {
|
2022-07-10 19:55:30 +00:00
|
|
|
grid-template-columns: 1fr;
|
|
|
|
|
}
|
2022-04-24 23:38:12 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-27 22:05:22 +00:00
|
|
|
.random-buttons {
|
2022-08-11 23:34:45 +00:00
|
|
|
display: flex;
|
|
|
|
|
place-content: space-between;
|
|
|
|
|
place-items: center;
|
|
|
|
|
|
|
|
|
|
@media (max-width: 650px) {
|
|
|
|
|
display: grid;
|
|
|
|
|
grid-template-columns: 1fr 1fr;
|
|
|
|
|
}
|
2022-04-24 23:38:12 +00:00
|
|
|
}
|
2022-01-28 05:27:12 +00:00
|
|
|
</style>
|