Fixing select fields on the API calls.

This commit is contained in:
Bradley Shellnut 2023-01-08 00:35:40 -08:00
parent 9f74e58a56
commit 554c28945f
6 changed files with 34 additions and 24 deletions

View file

@ -77,7 +77,7 @@
type="button" type="button"
on:click={() => { on:click={() => {
removeGameFromCollection(); removeGameFromCollection();
}}>Remove from Collection <MinusCircleIcon width="24" height="24" /></button }}><span>Remove from Collection</span> <MinusCircleIcon width="24" height="24" /></button
> >
{:else} {:else}
<button <button
@ -89,7 +89,7 @@
if (browser) { if (browser) {
localStorage.collection = JSON.stringify($collectionStore); localStorage.collection = JSON.stringify($collectionStore);
} }
}}>Add to collection <PlusCircleIcon width="24" height="24" /></button }}><span>Add to collection</span> <PlusCircleIcon width="24" height="24" /></button
> >
{/if} {/if}
{#if existsInWishlist} {#if existsInWishlist}
@ -99,7 +99,7 @@
type="button" type="button"
on:click={() => { on:click={() => {
removeGameFromWishlist(); removeGameFromWishlist();
}}>Remove from Wishlist <MinusCircleIcon width="24" height="24" /></button }}><span>Remove from Wishlist</span> <MinusCircleIcon width="24" height="24" /></button
> >
{:else} {:else}
<button <button
@ -111,7 +111,7 @@
if (browser) { if (browser) {
localStorage.wishlist = JSON.stringify($wishlistStore); localStorage.wishlist = JSON.stringify($wishlistStore);
} }
}}>Add to wishlist <PlusCircleIcon width="24" height="24" /></button }}><span>Add to wishlist</span> <PlusCircleIcon width="24" height="24" /></button
> >
{/if} {/if}
</div> </div>
@ -172,6 +172,7 @@
.btn { .btn {
max-height: 100px; max-height: 100px;
text-align: start;
} }
.remove { .remove {

View file

@ -55,7 +55,6 @@
} }
let placeholderList = [...Array(numberOfGameSkeleton).keys()]; let placeholderList = [...Array(numberOfGameSkeleton).keys()];
console.log(placeholderList);
if (form?.error) { if (form?.error) {
disclosureOpen = true; disclosureOpen = true;

View file

@ -5,21 +5,23 @@ import { convertToSavedGame } from './gameMapper';
import { saved_game_schema } from '../zodValidation'; import { saved_game_schema } from '../zodValidation';
export function addToCollection(game: GameType | SavedGameType) { export function addToCollection(game: GameType | SavedGameType) {
try { try {
saved_game_schema.parse(game); console.log(`Saving game: ${JSON.stringify(game)}`);
collectionStore.add(convertToSavedGame(game)); saved_game_schema.parse(game);
toast.send("Added to collection", { duration: 3000, type: ToastType.INFO }); collectionStore.add(convertToSavedGame(game));
} catch (error) { toast.send('Added to collection', { duration: 3000, type: ToastType.INFO });
toast.send('Error adding to collection', { duration: 3000, type: ToastType.ERROR }); } catch (error) {
} console.log(error);
toast.send('Error adding to collection', { duration: 3000, type: ToastType.ERROR });
}
} }
export function removeFromCollection(game: GameType | SavedGameType) { export function removeFromCollection(game: GameType | SavedGameType) {
try { try {
saved_game_schema.parse(game); saved_game_schema.parse(game);
collectionStore.remove(game.id); collectionStore.remove(game.id);
toast.send("Removed from collection", { duration: 3000, type: ToastType.INFO }); toast.send('Removed from collection', { duration: 3000, type: ToastType.INFO });
} catch (error) { } catch (error) {
toast.send('Error removing from collection', { duration: 3000, type: ToastType.ERROR }); toast.send('Error removing from collection', { duration: 3000, type: ToastType.ERROR });
} }
} }

View file

@ -4,7 +4,9 @@ import { boardGameApi } from '../../api';
export const load: PageServerLoad = async ({ params, setHeaders }) => { export const load: PageServerLoad = async ({ params, setHeaders }) => {
const queryParams = { const queryParams = {
ids: `${params?.id}` ids: `${params?.id}`,
fields:
'id,name,min_age,min_players,max_players,thumb_url,playtime,min_playtime,max_playtime,min_age,description,year_published,image_url'
}; };
const response = await boardGameApi('get', `search`, queryParams); const response = await boardGameApi('get', `search`, queryParams);
@ -16,8 +18,12 @@ export const load: PageServerLoad = async ({ params, setHeaders }) => {
'Cache-Control': 'max-age=3600' 'Cache-Control': 'max-age=3600'
}); });
const game = gameResponse?.games[0];
game.players = `${game.min_players}-${game.max_players}`;
game.playtime = `${game.min_playtime}-${game.max_playtime}`;
return { return {
game: gameResponse?.games[0] game
}; };
} }

View file

@ -21,7 +21,7 @@ export const load: PageServerLoad = async ({ fetch, url }) => {
fuzzy_match: true, fuzzy_match: true,
name: '', name: '',
fields: fields:
'id,name,minAge,minPlayers,maxPlayers,exactMinPlayers,exactMaxPlayers,thumb_url,players,playtime,min_age,description' 'id,name,min_age,min_players,max_players,thumb_url,min_playtime,max_playtime,min_age,description'
}; };
try { try {
@ -113,6 +113,8 @@ export const load: PageServerLoad = async ({ fetch, url }) => {
console.log('totalCount', totalCount); console.log('totalCount', totalCount);
const games: GameType[] = []; const games: GameType[] = [];
gameList.forEach((game) => { gameList.forEach((game) => {
game.players = `${game.min_players}-${game.max_players}`;
game.playtime = `${game.min_playtime}-${game.max_playtime}`;
games.push(mapAPIGameToBoredGame(game)); games.push(mapAPIGameToBoredGame(game));
}); });
@ -183,6 +185,8 @@ export const actions: Actions = {
console.log('totalCount', totalCount); console.log('totalCount', totalCount);
const games: GameType[] = []; const games: GameType[] = [];
gameList.forEach((game) => { gameList.forEach((game) => {
game.players = `${game.min_players}-${game.max_players}`;
game.playtime = `${game.min_playtime}-${game.max_playtime}`;
games.push(mapAPIGameToBoredGame(game)); games.push(mapAPIGameToBoredGame(game));
}); });

View file

@ -6,8 +6,6 @@
export let data: PageData; export let data: PageData;
export let form: ActionData; export let form: ActionData;
console.log('data limit', data?.limit);
$: if (data?.games) { $: if (data?.games) {
gameStore.removeAll(); gameStore.removeAll();
gameStore.addAll(data?.games); gameStore.addAll(data?.games);