From eaf286b5c945ac12a4cb5a9a6172a6e32dff06dd Mon Sep 17 00:00:00 2001 From: Bradley Shellnut Date: Mon, 29 Aug 2022 11:33:51 -0500 Subject: [PATCH] Adding collection route, header path to collection, minimal view of game for collection, and move save/clear to utils. --- src/lib/components/game/index.svelte | 41 ++++++++++++------- src/lib/components/header/Header.svelte | 14 +++---- .../preferences/gameCollection.svelte | 19 +-------- src/lib/types.ts | 1 + src/lib/util/manipulateCollection.ts | 16 ++++++++ src/routes/collection/+page.svelte | 2 +- 6 files changed, 51 insertions(+), 42 deletions(-) diff --git a/src/lib/components/game/index.svelte b/src/lib/components/game/index.svelte index d0be0ca..990545d 100644 --- a/src/lib/components/game/index.svelte +++ b/src/lib/components/game/index.svelte @@ -5,7 +5,8 @@ import { collectionStore } from '$lib/stores/collectionStore'; import { addToCollection, removeFromCollection } from '$lib/util/manipulateCollection'; - export let game: GameType; + export let game: GameType | SavedGameType; + export let minimal: boolean = false; export let detailed: boolean = false; $: existsInCollection = $collectionStore.find((item: SavedGameType) => item.id === game.id); @@ -18,22 +19,32 @@ -
-

{game.year_published}

-

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

-

{game.playtime} minutes

-

Minimum Age: {game.min_age}

- View Game - {#if detailed} -
{@html game.description}
- {/if} -
+ {#if !minimal && game?.year_published && game.players && game.max_players && game.playtime} +
+

{game.year_published}

+

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

+

{game.playtime} minutes

+

Minimum Age: {game.min_age}

+ View Game + {#if detailed} +
{@html game.description}
+ {/if} +
+ {/if} {#if existsInCollection} - {:else} - {/if} @@ -67,11 +78,11 @@ .game-container { display: flex; flex-wrap: wrap; - + @media (max-width: 650px) { max-width: none; } - + gap: var(--spacing-16); padding: var(--spacing-16) var(--spacing-16); transition: all 0.3s; diff --git a/src/lib/components/header/Header.svelte b/src/lib/components/header/Header.svelte index ac23bea..b3d5f0a 100644 --- a/src/lib/components/header/Header.svelte +++ b/src/lib/components/header/Header.svelte @@ -1,22 +1,18 @@
@@ -56,6 +52,7 @@ display: flex; justify-content: center; align-items: center; + gap: 2rem; margin: 1rem; --background: rgba(255, 255, 255, 0.7); } @@ -107,7 +104,7 @@ padding: 0 1em; color: var(--heading-color); font-weight: 700; - font-size: 0.8rem; + /* font-size: 0.8rem; */ text-transform: uppercase; letter-spacing: 0.1em; text-decoration: none; @@ -115,6 +112,7 @@ } a:hover { + text-decoration: underline; color: var(--accent-color); } diff --git a/src/lib/components/preferences/gameCollection.svelte b/src/lib/components/preferences/gameCollection.svelte index 6ed40e7..6e8762b 100644 --- a/src/lib/components/preferences/gameCollection.svelte +++ b/src/lib/components/preferences/gameCollection.svelte @@ -1,23 +1,6 @@
diff --git a/src/lib/types.ts b/src/lib/types.ts index c0e1c07..6944ee8 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -21,6 +21,7 @@ export type ToastData = { export type SavedGameType = { id: string; name: string; + thumb_url: string; } export type GameType = { diff --git a/src/lib/util/manipulateCollection.ts b/src/lib/util/manipulateCollection.ts index 5e05fe5..fcc20ba 100644 --- a/src/lib/util/manipulateCollection.ts +++ b/src/lib/util/manipulateCollection.ts @@ -1,11 +1,13 @@ import { collectionStore } from '$lib/stores/collectionStore'; import { toast } from '$lib/components/toast/toast'; import { ToastType, type GameType, type SavedGameType } from '$lib/types'; +import { browser } from '$app/env'; function convertToSavedGame(game: GameType): SavedGameType { return { id: game.id, name: game.name, + thumb_url: game.thumb_url, }; } @@ -18,3 +20,17 @@ export function removeFromCollection(game: GameType) { collectionStore.remove(game.id); toast.send("Removed from collection", { duration: 3000, type: ToastType.INFO }); } + +export function saveCollection() { + console.log('Saving collection'); + console.log('collectionStore', collectionStore); + if (!browser) return; + localStorage.collection = JSON.stringify(collectionStore); + toast.send('Saved collection', { duration: 3000, type: ToastType.INFO }); +} + +export function clearCollection() { + if (!browser) return; + localStorage.collection = []; + toast.send('Cleared collection', { duration: 3000, type: ToastType.INFO }); +} diff --git a/src/routes/collection/+page.svelte b/src/routes/collection/+page.svelte index 223b01d..1ad4b63 100644 --- a/src/routes/collection/+page.svelte +++ b/src/routes/collection/+page.svelte @@ -12,7 +12,7 @@
{#each $collectionStore as game} - + {/each}