diff --git a/src/lib/components/header/Header.svelte b/src/lib/components/header/Header.svelte index 0b34b04..9c20536 100644 --- a/src/lib/components/header/Header.svelte +++ b/src/lib/components/header/Header.svelte @@ -35,7 +35,7 @@ display: flex; justify-content: space-between; align-items: center; - box-shadow: var(--level-2); + /* box-shadow: var(--level-2); */ padding: 0 var(--containerPadding); font-size: 1.6rem; diff --git a/src/lib/components/loading.svelte b/src/lib/components/loading.svelte index 21f9f6d..66a902f 100644 --- a/src/lib/components/loading.svelte +++ b/src/lib/components/loading.svelte @@ -1,10 +1,20 @@ -
-
-
- \ No newline at end of file + diff --git a/src/routes/api/game/index.ts b/src/routes/api/game/index.ts new file mode 100644 index 0000000..caad145 --- /dev/null +++ b/src/routes/api/game/index.ts @@ -0,0 +1,60 @@ +import type { RequestHandler } from '@sveltejs/kit'; +import type { SearchQuery } from '$lib/types'; + +export const POST: RequestHandler = async ({ request }) => { + const form = await request.formData(); + console.log('form', form); + const queryParams: SearchQuery = { + order_by: 'rank', + ascending: false, + limit: 20, + client_id: import.meta.env.VITE_PUBLIC_CLIENT_ID, + fuzzy_match: true, + name: '', + }; + + queryParams.name = `${form.get('name')}`; + + const newQueryParams = {}; + for (const key in queryParams) { + console.log('key', key); + console.log('queryParams[key]', queryParams[key]); + newQueryParams[key] = `${queryParams[key]}`; + } + + const urlQueryParams = new URLSearchParams(newQueryParams); + + const url = `https://api.boardgameatlas.com/api/search${urlQueryParams ? `?${urlQueryParams}` : '' + }`; + const response = await fetch(url, { + method: 'get', + headers: { + 'content-type': 'application/json' + } + }); + console.log('response', response); + if (response.status === 404) { + // user hasn't created a todo list. + // start with an empty array + return { + body: { + games: [] + } + }; + } + + if (response.status === 200) { + const gameResponse = await response.json(); + const games = gameResponse?.games; + console.log('games', games); + return { + body: { + games: gameResponse?.games + } + }; + } + + return { + status: response.status + }; +}; diff --git a/src/routes/index.svelte b/src/routes/index.svelte index 26d4c6e..030f1aa 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -8,6 +8,7 @@ import Portal from '$lib/Portal.svelte'; import { gameStore } from '$lib/stores/gameSearchStore'; import { boredState } from '$lib/stores/boredState'; + import { Checkbox } from 'carbon-components-svelte'; // import { enhance } from "$lib/form"; // let games: GameType[] = []; @@ -31,6 +32,23 @@ // games = responseData?.games; } + 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(); + // submitting = false; + boredState.set({ loading: false }); + gameStore.removeAll(); + gameStore.addAll(responseData?.games); + } + + let name = ''; let minAge = 0; let minPlayers = 1; let maxPlayers = 1; @@ -46,6 +64,17 @@

Search Boardgames!

Input your requirements to search for board game that match your criteria

+
+
+
+ +
+
+ +
@@ -53,20 +82,6 @@ Min Age - -
- +
- +