Update toast to be in the bottom middle, error for fetching game data, fixing random from collection.

This commit is contained in:
Bradley Shellnut 2022-10-29 21:03:54 -05:00
parent 226c9454c7
commit 49464d3fba
10 changed files with 174 additions and 127 deletions

View file

@ -14,6 +14,8 @@
--background-without-opacity: rgba(255, 255, 255, 0.7); --background-without-opacity: rgba(255, 255, 255, 0.7);
--column-width: 42rem; --column-width: 42rem;
--column-margin-top: 4rem; --column-margin-top: 4rem;
--z-highest: 100;
--cardBorderRadius: 12px;
} }
body { body {

View file

@ -24,11 +24,11 @@
<div class="game-info"> <div class="game-info">
<h2>{game.name}</h2> <h2>{game.name}</h2>
<a class="thumbnail" href={`/game/${game.id}`}> <a class="thumbnail" href={`/game/${game.id}`}>
<img width="140" height="140" src={game.thumb_url} alt={`Image of ${game.name}`} /> <img src={game.thumb_url} alt={`Image of ${game.name}`} />
</a> </a>
</div> </div>
{#if !minimal} {#if !minimal && game?.players && game?.playtime}
<div class="game-details"> <div class="game-details">
{#if game.year_published} {#if game.year_published}
<p>{game.year_published}</p> <p>{game.year_published}</p>
@ -36,7 +36,7 @@
<p>{game.players} {game.max_players === 1 ? 'player' : 'players'}</p> <p>{game.players} {game.max_players === 1 ? 'player' : 'players'}</p>
<p>{game.playtime} minutes</p> <p>{game.playtime} minutes</p>
<p>Minimum Age: {game.min_age}</p> <p>Minimum Age: {game.min_age}</p>
<a href={`/game/${game.id}`}>View Game</a> <!-- <a href={`/game/${game.id}`}>View Game</a> -->
{#if detailed} {#if detailed}
<div class="description">{@html game.description}</div> <div class="description">{@html game.description}</div>
{/if} {/if}
@ -68,7 +68,7 @@
<style lang="scss"> <style lang="scss">
img { img {
border-radius: 10px; max-height: 200px;
} }
button { button {
@ -84,6 +84,7 @@
.game-container { .game-container {
display: flex; display: flex;
place-content: center;
flex-wrap: wrap; flex-wrap: wrap;
@media (max-width: 650px) { @media (max-width: 650px) {
@ -101,7 +102,8 @@
.game-info { .game-info {
display: grid; display: grid;
gap: 0.5rem; place-items: center;
gap: 0.75rem;
margin: 0.2rem; margin: 0.2rem;
} }

View file

@ -4,6 +4,7 @@
import { collectionStore } from '$lib/stores/collectionStore'; import { collectionStore } from '$lib/stores/collectionStore';
import { toast } from '$lib/components/toast/toast'; import { toast } from '$lib/components/toast/toast';
import { ToastType, type SavedGameType } from '$lib/types'; import { ToastType, type SavedGameType } from '$lib/types';
import { mapSavedGameToGame } from '$root/lib/util/gameMapper';
async function getRandomCollectionGame() { async function getRandomCollectionGame() {
if ($collectionStore.length > 0) { if ($collectionStore.length > 0) {
@ -12,13 +13,14 @@
if ($collectionStore.at(randomNumber)) { if ($collectionStore.at(randomNumber)) {
gameStore.removeAll(); gameStore.removeAll();
const randomGame: SavedGameType = $collectionStore.at(randomNumber)!; const randomGame: SavedGameType = $collectionStore.at(randomNumber)!;
const response = await fetch(`/api/game/${randomGame?.id}`, { // const response = await fetch(`/api/game/${randomGame?.id}`, {
method: 'GET', // method: 'GET',
headers: { accept: 'application/json' } // headers: { accept: 'application/json' }
}); // });
const responseData = await response.json(); // const responseData = await response.json();
console.log('responseData', responseData); // console.log('responseData', responseData);
gameStore.add(responseData?.game); // gameStore.add(responseData?.game);
const game = gameStore.add(mapSavedGameToGame(randomGame));
boredState.update((n) => ({ ...n, loading: false })); boredState.update((n) => ({ ...n, loading: false }));
} else { } else {
toast.send('Error!', { duration: 3000, type: ToastType.ERROR, dismissible: true }); toast.send('Error!', { duration: 3000, type: ToastType.ERROR, dismissible: true });

View file

@ -41,7 +41,11 @@
console.log('In success'); console.log('In success');
const resultGames = result?.data?.games; const resultGames = result?.data?.games;
if (resultGames?.length <= 0) { 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); gameStore.addAll(resultGames);
console.log(`Frontend result: ${JSON.stringify(result)}`); console.log(`Frontend result: ${JSON.stringify(result)}`);

View file

@ -12,6 +12,7 @@
<div <div
aria-label={toastData.dismissible ? 'Click to dismiss' : `${toastData.message}`} aria-label={toastData.dismissible ? 'Click to dismiss' : `${toastData.message}`}
on:click={() => toastData.dismissible && toast.remove(toastData.id)} on:click={() => toastData.dismissible && toast.remove(toastData.id)}
on:keydown={() => toastData.dismissible && toast.remove(toastData.id)}
in:fly={{ opacity: 0, x: 100 }} in:fly={{ opacity: 0, x: 100 }}
out:fade out:fade
animate:flip animate:flip
@ -47,24 +48,30 @@
<style lang="scss"> <style lang="scss">
.toast-wrapper { .toast-wrapper {
display: flex;
flex-flow: column;
align-items: center;
justify-content: center;
position: fixed; position: fixed;
bottom: 5px; bottom: 5vh;
right: 25px; width: 100vw;
z-index: calc(var(--z-highest) + 10);
} }
.toast { .toast {
display: flex; display: flex;
justify-content: center;
gap: 1rem; gap: 1rem;
place-items: center;
overflow: hidden; overflow: hidden;
position: relative; position: relative;
margin-bottom: 1rem; margin: 1rem 1rem 0;
min-width: 460px;
color: white; color: white;
background: var(--toast-background, #625df5); background: var(--toast-background, #625df5);
padding: 20px; padding: 1.5rem;
border-radius: 15px; border-radius: 12px;
box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.3); box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.3);
width: 30rem;
.close { .close {
padding: 5px; padding: 5px;

View file

@ -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 { export function mapAPIGameToBoredGame(game): GameType {
const { const {

View file

@ -1,4 +1,4 @@
<h1>The page you requested doesn't exist!</h1> <h1>The page you requested doesn't exist! 🤷‍♂️</h1>
<style> <style>
h1 { h1 {

View file

@ -90,7 +90,11 @@
console.log('In success'); console.log('In success');
const resultGames = result?.data?.games; const resultGames = result?.data?.games;
if (resultGames?.length <= 0) { 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); gameStore.addAll(resultGames);
totalItems = result?.data?.totalCount; totalItems = result?.data?.totalCount;

View file

@ -0,0 +1,12 @@
<h1>Unable to load board game info! 🤦‍♂️</h1>
<h2>Please try again later. 🙇🏼</h2>
<style>
h1,
h2 {
margin-top: var(--spacing-64);
font-family: var(--font-sans);
font-size: var(--font-32);
text-align: center;
}
</style>

View file

@ -127,6 +127,10 @@
margin-bottom: 3rem; margin-bottom: 3rem;
} }
img {
max-width: 500px;
}
button { button {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;