mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Pairing down API Game response objects, spacing for buttons, start form cleanup.
This commit is contained in:
parent
7d775608cd
commit
9bef4328cb
8 changed files with 92 additions and 27 deletions
|
|
@ -22,7 +22,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
let submitting = $boredState?.loading;
|
let submitting = $boredState?.loading;
|
||||||
let minAge = 0;
|
let minAge = 1;
|
||||||
let minPlayers = 1;
|
let minPlayers = 1;
|
||||||
let maxPlayers = 1;
|
let maxPlayers = 1;
|
||||||
let exactMinAge = false;
|
let exactMinAge = false;
|
||||||
|
|
@ -34,7 +34,7 @@
|
||||||
<fieldset aria-busy={submitting} disabled={submitting}>
|
<fieldset aria-busy={submitting} disabled={submitting}>
|
||||||
<div>
|
<div>
|
||||||
<label htmlfor="minAge">
|
<label htmlfor="minAge">
|
||||||
<input id="minAge" name="minAge" bind:value={minAge} type="number" min={0} max={120} />
|
<input id="minAge" name="minAge" bind:value={minAge} type="number" min={1} max={120} />
|
||||||
Min Age
|
Min Age
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
<form on:submit|preventDefault={handleSubmit} method="post">
|
<form on:submit|preventDefault={handleSubmit} method="post">
|
||||||
<fieldset aria-busy={submitting} disabled={submitting}>
|
<fieldset aria-busy={submitting} disabled={submitting}>
|
||||||
<input type="checkbox" id="random" name="random" hidden checked />
|
<input type="checkbox" id="random" name="random" hidden checked />
|
||||||
<button type="submit" disabled={submitting}>Random Game 🎲</button>
|
<button class="btn" type="submit" disabled={submitting}>Random Game 🎲</button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
@ -35,11 +35,11 @@
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
button {
|
button {
|
||||||
border-radius: 10px;
|
/* border-radius: 10px; */
|
||||||
margin: 0.5rem;
|
/* margin: 0.5rem; */
|
||||||
padding: 1rem;
|
/* padding: 1rem; */
|
||||||
color: var(--clr-input-txt);
|
/* color: var(--clr-input-txt); */
|
||||||
background-color: var(--color-btn-primary-active);
|
/* background-color: var(--color-btn-primary-active); */
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldset {
|
fieldset {
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
<div>
|
<div>
|
||||||
<label htmlfor="name">
|
<label htmlfor="name">
|
||||||
Search
|
Search
|
||||||
<input id="name" name="name" bind:value={name} type="text" />
|
<input id="name" name="name" bind:value={name} type="text" placeholder="Enter name" />
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
|
||||||
52
src/lib/util/gameMapper.ts
Normal file
52
src/lib/util/gameMapper.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
import type { GameType } from "$lib/types";
|
||||||
|
|
||||||
|
export function mapAPIGameToBoredGame(game): GameType {
|
||||||
|
const {
|
||||||
|
id,
|
||||||
|
handle,
|
||||||
|
name,
|
||||||
|
url,
|
||||||
|
edit_url,
|
||||||
|
thumb_url,
|
||||||
|
image_url,
|
||||||
|
price,
|
||||||
|
price_ca,
|
||||||
|
price_uk,
|
||||||
|
price_au,
|
||||||
|
msrp,
|
||||||
|
year_published,
|
||||||
|
min_players,
|
||||||
|
max_players,
|
||||||
|
min_playtime,
|
||||||
|
max_playtime,
|
||||||
|
min_age,
|
||||||
|
description,
|
||||||
|
description_preview,
|
||||||
|
players,
|
||||||
|
playtime,
|
||||||
|
} = game;
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
handle,
|
||||||
|
name,
|
||||||
|
url,
|
||||||
|
edit_url,
|
||||||
|
thumb_url,
|
||||||
|
image_url,
|
||||||
|
price,
|
||||||
|
price_ca,
|
||||||
|
price_uk,
|
||||||
|
price_au,
|
||||||
|
msrp,
|
||||||
|
year_published,
|
||||||
|
min_players,
|
||||||
|
max_players,
|
||||||
|
min_playtime,
|
||||||
|
max_playtime,
|
||||||
|
min_age,
|
||||||
|
description,
|
||||||
|
description_preview,
|
||||||
|
players,
|
||||||
|
playtime,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import type { RequestHandler } from '@sveltejs/kit';
|
import type { RequestHandler } from '@sveltejs/kit';
|
||||||
import type { SearchQuery } from '$lib/types';
|
import type { GameType, SearchQuery } from '$lib/types';
|
||||||
|
import { mapAPIGameToBoredGame } from '$lib/util/gameMapper';
|
||||||
|
|
||||||
export const POST: RequestHandler = async ({ request }) => {
|
export const POST: RequestHandler = async ({ request }) => {
|
||||||
const form = await request.formData();
|
const form = await request.formData();
|
||||||
|
|
@ -84,7 +85,7 @@ export const POST: RequestHandler = async ({ request }) => {
|
||||||
'content-type': 'application/json'
|
'content-type': 'application/json'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log('response', response);
|
// console.log('response', response);
|
||||||
if (response.status === 404) {
|
if (response.status === 404) {
|
||||||
// user hasn't created a todo list.
|
// user hasn't created a todo list.
|
||||||
// start with an empty array
|
// start with an empty array
|
||||||
|
|
@ -97,11 +98,17 @@ export const POST: RequestHandler = async ({ request }) => {
|
||||||
|
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
const gameResponse = await response.json();
|
const gameResponse = await response.json();
|
||||||
const games = gameResponse?.games;
|
const gameList = gameResponse?.games;
|
||||||
|
console.log('gameList', gameList);
|
||||||
|
console.log('type', typeof gameList);
|
||||||
|
const games: GameType[] = [];
|
||||||
|
gameList.forEach(game => {
|
||||||
|
games.push(mapAPIGameToBoredGame(game))
|
||||||
|
});
|
||||||
console.log('games', games);
|
console.log('games', games);
|
||||||
return {
|
return {
|
||||||
body: {
|
body: {
|
||||||
games: gameResponse?.games
|
games,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,13 @@
|
||||||
|
|
||||||
<h1>Search Boardgames!</h1>
|
<h1>Search Boardgames!</h1>
|
||||||
<p>Input your requirements to search for board game that match your criteria</p>
|
<p>Input your requirements to search for board game that match your criteria</p>
|
||||||
<div class="game-form">
|
<div class="game-search">
|
||||||
<TextSearch />
|
<TextSearch />
|
||||||
<AdvancedSearch />
|
<AdvancedSearch />
|
||||||
<RandomSearch />
|
<div class="random-buttons">
|
||||||
<Random />
|
<RandomSearch />
|
||||||
|
<Random />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- {#if submitting}
|
<!-- {#if submitting}
|
||||||
|
|
@ -99,22 +101,26 @@
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.game-form {
|
.game-search {
|
||||||
margin: 1rem;
|
margin: 1rem;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
box-shadow: var(--level-2);
|
box-shadow: var(--level-2);
|
||||||
background: rgba(0, 0, 0, 0.02);
|
background: rgba(0, 0, 0, 0.02);
|
||||||
border: 2px solid var(--clr-primary);
|
border: 2px solid var(--clr-primary);
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
|
|
||||||
|
fieldset {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, 1fr);
|
||||||
|
}
|
||||||
|
label {
|
||||||
|
display: grid;
|
||||||
|
margin: 1rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.game-form fieldset {
|
.random-buttons {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(3, 1fr);
|
grid-template-columns: 1fr 1fr;
|
||||||
}
|
|
||||||
|
|
||||||
.game-form label {
|
|
||||||
display: grid;
|
|
||||||
margin: 1rem;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -218,7 +218,7 @@ input {
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn {
|
.btn {
|
||||||
padding: var(--spacing-16) var(--spacing-32);
|
padding: var(--spacing-4) var(--spacing-8);
|
||||||
font-size: var(--font-18);
|
font-size: var(--font-18);
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: var(--color-text-primary);
|
color: var(--color-text-primary);
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ const config = {
|
||||||
// Override http methods in the Todo forms
|
// Override http methods in the Todo forms
|
||||||
methodOverride: {
|
methodOverride: {
|
||||||
allowed: ['PATCH', 'DELETE']
|
allowed: ['PATCH', 'DELETE']
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default config;
|
export default config;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue