From 554c28945fea03af0480621aa7341284cced79d1 Mon Sep 17 00:00:00 2001 From: Bradley Shellnut Date: Sun, 8 Jan 2023 00:35:40 -0800 Subject: [PATCH] Fixing select fields on the API calls. --- src/lib/components/game/index.svelte | 9 +++--- .../components/search/textSearch/index.svelte | 1 - src/lib/util/manipulateCollection.ts | 30 ++++++++++--------- src/routes/game/[id]/+page.server.ts | 10 +++++-- src/routes/search/+page.server.ts | 6 +++- src/routes/search/+page.svelte | 2 -- 6 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/lib/components/game/index.svelte b/src/lib/components/game/index.svelte index 6cc7f40..7149077 100644 --- a/src/lib/components/game/index.svelte +++ b/src/lib/components/game/index.svelte @@ -77,7 +77,7 @@ type="button" on:click={() => { removeGameFromCollection(); - }}>Remove from Collection Remove from Collection {:else} Add to collection {/if} {#if existsInWishlist} @@ -99,7 +99,7 @@ type="button" on:click={() => { removeGameFromWishlist(); - }}>Remove from Wishlist Remove from Wishlist {:else} Add to wishlist {/if} @@ -172,6 +172,7 @@ .btn { max-height: 100px; + text-align: start; } .remove { diff --git a/src/lib/components/search/textSearch/index.svelte b/src/lib/components/search/textSearch/index.svelte index 65076ee..2410c64 100644 --- a/src/lib/components/search/textSearch/index.svelte +++ b/src/lib/components/search/textSearch/index.svelte @@ -55,7 +55,6 @@ } let placeholderList = [...Array(numberOfGameSkeleton).keys()]; - console.log(placeholderList); if (form?.error) { disclosureOpen = true; diff --git a/src/lib/util/manipulateCollection.ts b/src/lib/util/manipulateCollection.ts index ee87199..4ba80e9 100644 --- a/src/lib/util/manipulateCollection.ts +++ b/src/lib/util/manipulateCollection.ts @@ -5,21 +5,23 @@ import { convertToSavedGame } from './gameMapper'; import { saved_game_schema } from '../zodValidation'; export function addToCollection(game: GameType | SavedGameType) { - try { - saved_game_schema.parse(game); - collectionStore.add(convertToSavedGame(game)); - toast.send("Added to collection", { duration: 3000, type: ToastType.INFO }); - } catch (error) { - toast.send('Error adding to collection', { duration: 3000, type: ToastType.ERROR }); - } + try { + console.log(`Saving game: ${JSON.stringify(game)}`); + saved_game_schema.parse(game); + collectionStore.add(convertToSavedGame(game)); + toast.send('Added to collection', { duration: 3000, type: ToastType.INFO }); + } catch (error) { + console.log(error); + toast.send('Error adding to collection', { duration: 3000, type: ToastType.ERROR }); + } } export function removeFromCollection(game: GameType | SavedGameType) { - try { - saved_game_schema.parse(game); - collectionStore.remove(game.id); - toast.send("Removed from collection", { duration: 3000, type: ToastType.INFO }); - } catch (error) { - toast.send('Error removing from collection', { duration: 3000, type: ToastType.ERROR }); - } + try { + saved_game_schema.parse(game); + collectionStore.remove(game.id); + toast.send('Removed from collection', { duration: 3000, type: ToastType.INFO }); + } catch (error) { + toast.send('Error removing from collection', { duration: 3000, type: ToastType.ERROR }); + } } diff --git a/src/routes/game/[id]/+page.server.ts b/src/routes/game/[id]/+page.server.ts index 0822867..a072f86 100644 --- a/src/routes/game/[id]/+page.server.ts +++ b/src/routes/game/[id]/+page.server.ts @@ -4,7 +4,9 @@ import { boardGameApi } from '../../api'; export const load: PageServerLoad = async ({ params, setHeaders }) => { 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); @@ -16,8 +18,12 @@ export const load: PageServerLoad = async ({ params, setHeaders }) => { '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 { - game: gameResponse?.games[0] + game }; } diff --git a/src/routes/search/+page.server.ts b/src/routes/search/+page.server.ts index 89f0801..996c269 100644 --- a/src/routes/search/+page.server.ts +++ b/src/routes/search/+page.server.ts @@ -21,7 +21,7 @@ export const load: PageServerLoad = async ({ fetch, url }) => { fuzzy_match: true, name: '', 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 { @@ -113,6 +113,8 @@ export const load: PageServerLoad = async ({ fetch, url }) => { console.log('totalCount', totalCount); const games: GameType[] = []; gameList.forEach((game) => { + game.players = `${game.min_players}-${game.max_players}`; + game.playtime = `${game.min_playtime}-${game.max_playtime}`; games.push(mapAPIGameToBoredGame(game)); }); @@ -183,6 +185,8 @@ export const actions: Actions = { console.log('totalCount', totalCount); const games: GameType[] = []; gameList.forEach((game) => { + game.players = `${game.min_players}-${game.max_players}`; + game.playtime = `${game.min_playtime}-${game.max_playtime}`; games.push(mapAPIGameToBoredGame(game)); }); diff --git a/src/routes/search/+page.svelte b/src/routes/search/+page.svelte index 35392ab..c68a6b5 100644 --- a/src/routes/search/+page.svelte +++ b/src/routes/search/+page.svelte @@ -6,8 +6,6 @@ export let data: PageData; export let form: ActionData; - console.log('data limit', data?.limit); - $: if (data?.games) { gameStore.removeAll(); gameStore.addAll(data?.games);