From 49464d3fba0885ecd9fa5341096d363dfce698e7 Mon Sep 17 00:00:00 2001 From: Bradley Shellnut Date: Sat, 29 Oct 2022 21:03:54 -0500 Subject: [PATCH] Update toast to be in the bottom middle, error for fetching game data, fixing random from collection. --- src/app.css | 2 + src/lib/components/game/index.svelte | 12 +- src/lib/components/random/index.svelte | 76 ++++----- src/lib/components/search/random/index.svelte | 6 +- src/lib/components/toast/Toast.svelte | 157 +++++++++--------- src/lib/util/gameMapper.ts | 12 +- src/routes/+error.svelte | 14 +- src/routes/+page.svelte | 6 +- src/routes/game/[id]/+error.svelte | 12 ++ src/routes/game/[id]/+page.svelte | 4 + 10 files changed, 174 insertions(+), 127 deletions(-) create mode 100644 src/routes/game/[id]/+error.svelte diff --git a/src/app.css b/src/app.css index fc55fb0..cee552d 100644 --- a/src/app.css +++ b/src/app.css @@ -14,6 +14,8 @@ --background-without-opacity: rgba(255, 255, 255, 0.7); --column-width: 42rem; --column-margin-top: 4rem; + --z-highest: 100; + --cardBorderRadius: 12px; } body { diff --git a/src/lib/components/game/index.svelte b/src/lib/components/game/index.svelte index 8463a4a..68f8361 100644 --- a/src/lib/components/game/index.svelte +++ b/src/lib/components/game/index.svelte @@ -24,11 +24,11 @@

{game.name}

- {`Image + {`Image
- {#if !minimal} + {#if !minimal && game?.players && game?.playtime}
{#if game.year_published}

{game.year_published}

@@ -36,7 +36,7 @@

{game.players} {game.max_players === 1 ? 'player' : 'players'}

{game.playtime} minutes

Minimum Age: {game.min_age}

- View Game + {#if detailed}
{@html game.description}
{/if} @@ -68,7 +68,7 @@ diff --git a/src/lib/components/search/random/index.svelte b/src/lib/components/search/random/index.svelte index 6972972..c55e5d3 100644 --- a/src/lib/components/search/random/index.svelte +++ b/src/lib/components/search/random/index.svelte @@ -41,7 +41,11 @@ console.log('In success'); const resultGames = result?.data?.games; if (resultGames?.length <= 0) { - toast.send('No results!', { duration: 3000, type: ToastType.INFO, dismissible: true }); + toast.send('No results found 😿', { + duration: 3000, + type: ToastType.INFO, + dismissible: true + }); } gameStore.addAll(resultGames); console.log(`Frontend result: ${JSON.stringify(result)}`); diff --git a/src/lib/components/toast/Toast.svelte b/src/lib/components/toast/Toast.svelte index c703b8a..1b495a5 100644 --- a/src/lib/components/toast/Toast.svelte +++ b/src/lib/components/toast/Toast.svelte @@ -1,87 +1,94 @@ -
- {#each $toast as toastData (toastData.id)} -
toastData.dismissible && toast.remove(toastData.id)} - in:fly={{ opacity: 0, x: 100 }} - out:fade - animate:flip - class={`toast ${toastData.type.toLowerCase()}`} - > - - {#if toastData.dismissible && toastData.showButton} - - {/if} -
- {/each} -
+
+ {#each $toast as toastData (toastData.id)} +
toastData.dismissible && toast.remove(toastData.id)} + on:keydown={() => toastData.dismissible && toast.remove(toastData.id)} + in:fly={{ opacity: 0, x: 100 }} + out:fade + animate:flip + class={`toast ${toastData.type.toLowerCase()}`} + > + + {#if toastData.dismissible && toastData.showButton} + + {/if} +
+ {/each} +
diff --git a/src/lib/util/gameMapper.ts b/src/lib/util/gameMapper.ts index e7e73ce..7164c6c 100644 --- a/src/lib/util/gameMapper.ts +++ b/src/lib/util/gameMapper.ts @@ -1,4 +1,14 @@ -import type { GameType } from '$lib/types'; +import type { GameType, SavedGameType } from '$lib/types'; + +export function mapSavedGameToGame(game: SavedGameType): GameType { + const { id, name, thumb_url } = game; + + return { + id, + name, + thumb_url + }; +} export function mapAPIGameToBoredGame(game): GameType { const { diff --git a/src/routes/+error.svelte b/src/routes/+error.svelte index b15ccf6..4219fba 100644 --- a/src/routes/+error.svelte +++ b/src/routes/+error.svelte @@ -1,10 +1,10 @@ -

The page you requested doesn't exist!

+

The page you requested doesn't exist! 🤷‍♂️

diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 6f34b47..23dc4a3 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -90,7 +90,11 @@ console.log('In success'); const resultGames = result?.data?.games; if (resultGames?.length <= 0) { - toast.send('No results!', { duration: 3000, type: ToastType.INFO, dismissible: true }); + toast.send('No results found 😿', { + duration: 3000, + type: ToastType.ERROR, + dismissible: true + }); } gameStore.addAll(resultGames); totalItems = result?.data?.totalCount; diff --git a/src/routes/game/[id]/+error.svelte b/src/routes/game/[id]/+error.svelte new file mode 100644 index 0000000..b37b80d --- /dev/null +++ b/src/routes/game/[id]/+error.svelte @@ -0,0 +1,12 @@ +

Unable to load board game info! 🤦‍♂️

+

Please try again later. 🙇🏼

+ + diff --git a/src/routes/game/[id]/+page.svelte b/src/routes/game/[id]/+page.svelte index 881f3e7..7233fe1 100644 --- a/src/routes/game/[id]/+page.svelte +++ b/src/routes/game/[id]/+page.svelte @@ -127,6 +127,10 @@ margin-bottom: 3rem; } + img { + max-width: 500px; + } + button { display: flex; justify-content: space-between;