diff --git a/src/lib/components/SkeletonPlaceholder.svelte b/src/lib/components/SkeletonPlaceholder.svelte new file mode 100644 index 0000000..d94d899 --- /dev/null +++ b/src/lib/components/SkeletonPlaceholder.svelte @@ -0,0 +1,115 @@ + + + + +
+ + diff --git a/src/lib/components/game/index.svelte b/src/lib/components/game/index.svelte index f269c3b..04346a8 100644 --- a/src/lib/components/game/index.svelte +++ b/src/lib/components/game/index.svelte @@ -10,7 +10,6 @@ import { browser } from '$app/environment'; export let game: GameType | SavedGameType; - export let minimal: boolean = false; export let detailed: boolean = false; const dispatch = createEventDispatcher(); @@ -23,6 +22,24 @@ dispatch('handleRemoveCollection', game); } + // Naive and assumes description is only on our GameType at the moment + function isGameType(game: GameType | SavedGameType): game is GameType { + return (game as GameType).description !== undefined; + } + + // function lazy(img: HTMLImageElement) { + // function loaded() { + // img.classList.add('loaded'); + // img.classList.remove('loading'); + // } + // if (img.complete) { + // loaded(); + // } else { + // img.classList.add('loading'); + // img.onload = () => loaded(); + // } + // } + $: existsInCollection = $collectionStore.find((item: SavedGameType) => item.id === game.id); $: existsInWishlist = $wishlistStore.find((item: SavedGameType) => item.id === game.id); @@ -31,15 +48,16 @@

{game.name}

{`Image +
-

Players: {game.min_players} - {game.max_players}

+

Players: {game.players}

Time: {game.playtime} minutes

- {#if game?.min_age} + {#if isGameType(game) && game?.min_age}

Min Age: {game.min_age}

{/if} - {#if detailed} + {#if detailed && isGameType(game) && game?.description}
{@html game.description}
{/if}
diff --git a/src/lib/components/random/index.svelte b/src/lib/components/random/index.svelte index 2dc419e..fd9324a 100644 --- a/src/lib/components/random/index.svelte +++ b/src/lib/components/random/index.svelte @@ -20,7 +20,7 @@ // const responseData = await response.json(); // console.log('responseData', responseData); // gameStore.add(responseData?.game); - const game = gameStore.add(mapSavedGameToGame(randomGame)); + gameStore.add(mapSavedGameToGame(randomGame)); boredState.update((n) => ({ ...n, loading: false })); } else { toast.send('Error!', { duration: 3000, type: ToastType.ERROR, dismissible: true }); diff --git a/src/lib/components/search/advancedSearch/index.svelte b/src/lib/components/search/advancedSearch/index.svelte index 98babf2..4c7ea50 100644 --- a/src/lib/components/search/advancedSearch/index.svelte +++ b/src/lib/components/search/advancedSearch/index.svelte @@ -5,11 +5,11 @@ export let form: ActionData; console.log('advanced search form', form); let submitting = $boredState?.loading; - let minAge = 1; - let minPlayers = 1; - let maxPlayers = 1; - let exactMinPlayers = false; - let exactMaxPlayers = false; + let minAge = form?.minAge || 1; + let minPlayers = form?.minPlayers || 1; + let maxPlayers = form?.maxPlayers || 1; + let exactMinPlayers = form?.exactMinPlayers || false; + let exactMaxPlayers = form?.exactMaxPlayers || false;
+ {#if $gameStore?.length > 0}

Games Found:

@@ -138,7 +140,6 @@ {/each} diff --git a/src/routes/game/[id]/+page.svelte b/src/routes/game/[id]/+page.svelte index 33ab6e0..12cd2ce 100644 --- a/src/routes/game/[id]/+page.svelte +++ b/src/routes/game/[id]/+page.svelte @@ -9,6 +9,7 @@ } from '@rgossiaux/svelte-heroicons/outline'; import type { GameType, SavedGameType } from '$lib/types'; import { collectionStore } from '$lib/stores/collectionStore'; + import { wishlistStore } from '$lib/stores/wishlistStore'; import Button from '$lib/components/button/index.svelte'; import RemoveCollectionDialog from '$root/lib/components/dialog/RemoveCollectionDialog.svelte'; import { addToCollection } from '$lib/util/manipulateCollection'; @@ -16,30 +17,34 @@ import { boredState } from '$root/lib/stores/boredState'; import { browser } from '$app/environment'; import LinkWithIcon from '$root/lib/components/LinkWithIcon.svelte'; + import { addToWishlist } from '$root/lib/util/manipulateWishlist'; + import RemoveWishlistDialog from '$root/lib/components/dialog/RemoveWishlistDialog.svelte'; $: existsInCollection = $collectionStore.find((item: SavedGameType) => item.id === game.id); + $: existsInWishlist = $wishlistStore.find((item: SavedGameType) => item.id === game.id); export let data: PageData; export let game: GameType = data?.game; - console.log('page game', game); let seeMore: boolean = false; - console.log(game?.description?.indexOf('

')); let firstParagraphEnd = 0; if (game?.description?.indexOf('

') > 0) { firstParagraphEnd = game?.description?.indexOf('

') + 4; } else if (game?.description?.indexOf('') > 0) { firstParagraphEnd = game?.description?.indexOf('') + 5; } - console.log('firstParagraphEnd', firstParagraphEnd); - function removeGame() { + function remoceFromCollection() { boredState.update((n) => ({ ...n, dialog: { isOpen: true, content: RemoveCollectionDialog, additionalData: game } })); - if (browser) { - localStorage.collection = JSON.stringify($collectionStore); - } + } + + function removeFromWishList() { + boredState.update((n) => ({ + ...n, + dialog: { isOpen: true, content: RemoveWishlistDialog, additionalData: game } + })); } @@ -55,7 +60,7 @@ {`Image
-
+

Year: {game?.year_published}

Players: {game.players}

@@ -70,7 +75,7 @@
{#if existsInCollection} - {:else} @@ -89,6 +94,27 @@ {/if}
+
+ {#if existsInWishlist} + + {:else} + + {/if} +
{#if firstParagraphEnd > 0}