2022-07-11 04:17:59 +00:00
|
|
|
<script lang="ts">
|
2022-10-31 04:08:33 +00:00
|
|
|
import { fade, fly } from 'svelte/transition';
|
2022-10-27 02:38:30 +00:00
|
|
|
import {
|
|
|
|
|
ExternalLinkIcon,
|
|
|
|
|
MinusCircleIcon,
|
|
|
|
|
MinusIcon,
|
|
|
|
|
PlusCircleIcon,
|
|
|
|
|
PlusIcon
|
|
|
|
|
} from '@rgossiaux/svelte-heroicons/outline';
|
|
|
|
|
import type { GameType, SavedGameType } from '$lib/types';
|
|
|
|
|
import { collectionStore } from '$lib/stores/collectionStore';
|
|
|
|
|
import RemoveCollectionDialog from '$root/lib/components/dialog/RemoveCollectionDialog.svelte';
|
|
|
|
|
import { addToCollection } from '$lib/util/manipulateCollection';
|
|
|
|
|
import type { PageData } from './$types';
|
|
|
|
|
import { boredState } from '$root/lib/stores/boredState';
|
|
|
|
|
import { browser } from '$app/environment';
|
2022-07-11 04:17:59 +00:00
|
|
|
|
2022-10-27 02:38:30 +00:00
|
|
|
$: existsInCollection = $collectionStore.find((item: SavedGameType) => item.id === game.id);
|
2022-09-01 02:32:30 +00:00
|
|
|
|
2022-10-27 02:38:30 +00:00
|
|
|
export let data: PageData;
|
|
|
|
|
export let game: GameType = data?.game;
|
|
|
|
|
console.log('page game', game);
|
|
|
|
|
let seeMore: boolean = false;
|
|
|
|
|
console.log(game?.description?.indexOf('</p>'));
|
|
|
|
|
let firstParagraphEnd = 0;
|
|
|
|
|
if (game?.description?.indexOf('</p>') > 0) {
|
|
|
|
|
firstParagraphEnd = game?.description?.indexOf('</p>') + 4;
|
|
|
|
|
} else if (game?.description?.indexOf('</ p>') > 0) {
|
|
|
|
|
firstParagraphEnd = game?.description?.indexOf('</ p>') + 5;
|
|
|
|
|
}
|
|
|
|
|
console.log('firstParagraphEnd', firstParagraphEnd);
|
2022-09-01 02:32:30 +00:00
|
|
|
|
2022-10-27 02:38:30 +00:00
|
|
|
function removeGame() {
|
|
|
|
|
boredState.update((n) => ({
|
|
|
|
|
...n,
|
|
|
|
|
dialog: { isOpen: true, content: RemoveCollectionDialog, additionalData: game }
|
|
|
|
|
}));
|
|
|
|
|
if (browser) {
|
|
|
|
|
localStorage.collection = JSON.stringify($collectionStore);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-11 04:17:59 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<svelte:head>
|
2022-10-27 02:38:30 +00:00
|
|
|
<title>{game?.name} | Bored Game</title>
|
2022-07-11 04:17:59 +00:00
|
|
|
</svelte:head>
|
|
|
|
|
|
|
|
|
|
<h2>{game?.name}</h2>
|
|
|
|
|
|
2022-10-27 22:10:32 +00:00
|
|
|
<section class="game">
|
2022-10-27 02:38:30 +00:00
|
|
|
<div>
|
|
|
|
|
<a class="thumbnail" href={game.url}>
|
|
|
|
|
<img src={game.image_url} alt={`Image of ${game.name}`} />
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
2022-10-31 04:08:33 +00:00
|
|
|
<div style="display: grid; place-items: center;">
|
|
|
|
|
<div class="details">
|
|
|
|
|
<p>Year Published: {game?.year_published}</p>
|
|
|
|
|
<p>Players: {game.players} {game.max_players === 1 ? 'player' : 'players'}</p>
|
|
|
|
|
<p>Playtime: {game.playtime} minutes</p>
|
|
|
|
|
<p>Minimum Age: {game.min_age}</p>
|
|
|
|
|
{#if +game?.price !== 0.0}
|
|
|
|
|
<p>Price: ${game?.price}</p>
|
|
|
|
|
{/if}
|
|
|
|
|
<a
|
|
|
|
|
class="with-icon"
|
|
|
|
|
href={game.url}
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noreferrer"
|
|
|
|
|
aria-label={`Board Game Atlas Link for ${game.name}`}
|
|
|
|
|
>Board Game Atlas <ExternalLinkIcon width="24" height="24" /></a
|
2022-10-27 02:38:30 +00:00
|
|
|
>
|
2022-10-31 04:08:33 +00:00
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
{#if existsInCollection}
|
2022-11-01 16:49:10 +00:00
|
|
|
<button class="btn button-icon remove" type="button" on:click={() => removeGame()}
|
2022-10-31 04:08:33 +00:00
|
|
|
>Remove from collection <MinusCircleIcon width="24" height="24" /></button
|
|
|
|
|
>
|
|
|
|
|
{:else}
|
|
|
|
|
<button
|
|
|
|
|
class="btn"
|
|
|
|
|
type="button"
|
|
|
|
|
on:click={() => {
|
|
|
|
|
addToCollection(game);
|
|
|
|
|
if (browser) {
|
|
|
|
|
localStorage.collection = JSON.stringify($collectionStore);
|
|
|
|
|
}
|
|
|
|
|
}}>Add to collection <PlusCircleIcon width="24" height="24" /></button
|
|
|
|
|
>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
2022-10-27 02:38:30 +00:00
|
|
|
</div>
|
2022-07-11 04:17:59 +00:00
|
|
|
</section>
|
2022-07-12 02:53:50 +00:00
|
|
|
{#if firstParagraphEnd > 0}
|
2022-10-31 15:25:02 +00:00
|
|
|
<section class="description" style="margin-top: 2rem;">
|
2022-10-31 02:06:26 +00:00
|
|
|
{@html game?.description?.substring(0, firstParagraphEnd)}
|
|
|
|
|
</section>
|
|
|
|
|
{#if game?.description?.substring(firstParagraphEnd + 1) !== ''}
|
2022-10-31 04:08:33 +00:00
|
|
|
<section class="description">
|
2022-10-27 02:38:30 +00:00
|
|
|
{#if seeMore}
|
2022-10-31 15:25:02 +00:00
|
|
|
<div class="overflow-description" in:fly={{ opacity: 0, x: 100 }} out:fade>
|
2022-10-31 04:08:33 +00:00
|
|
|
{@html game?.description?.substring(firstParagraphEnd + 1)}
|
|
|
|
|
</div>
|
2022-10-27 02:38:30 +00:00
|
|
|
{/if}
|
2022-10-31 04:08:33 +00:00
|
|
|
<button class="btn button-icon" type="button" on:click={() => (seeMore = !seeMore)}
|
2022-10-27 02:38:30 +00:00
|
|
|
>See
|
|
|
|
|
{#if !seeMore}
|
|
|
|
|
More <PlusIcon width="24" height="24" />
|
|
|
|
|
{:else}
|
|
|
|
|
Less <MinusIcon width="24" height="24" />
|
|
|
|
|
{/if}
|
|
|
|
|
</button>
|
2022-10-31 02:06:26 +00:00
|
|
|
</section>
|
|
|
|
|
{/if}
|
2022-08-26 22:53:23 +00:00
|
|
|
{:else}
|
2022-10-27 02:38:30 +00:00
|
|
|
<section class="description">
|
|
|
|
|
<span>
|
|
|
|
|
{@html game?.description}
|
|
|
|
|
</span>
|
|
|
|
|
</section>
|
2022-07-12 02:53:50 +00:00
|
|
|
{/if}
|
2022-07-11 04:17:59 +00:00
|
|
|
|
|
|
|
|
<style lang="scss">
|
2022-10-27 02:38:30 +00:00
|
|
|
h2 {
|
|
|
|
|
text-align: center;
|
|
|
|
|
font-size: 2.5rem;
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
margin-bottom: 3rem;
|
|
|
|
|
}
|
2022-07-11 04:17:59 +00:00
|
|
|
|
2022-10-27 02:38:30 +00:00
|
|
|
button {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
margin: 0;
|
|
|
|
|
padding: 1rem;
|
|
|
|
|
max-width: 30rem;
|
|
|
|
|
background-color: var(--color-btn-primary-active);
|
|
|
|
|
}
|
2022-07-11 04:17:59 +00:00
|
|
|
|
2022-11-01 16:49:10 +00:00
|
|
|
.remove {
|
|
|
|
|
background-color: var(--warning);
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
background-color: var(--warning-hover);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-31 04:08:33 +00:00
|
|
|
.button-icon {
|
|
|
|
|
display: grid;
|
|
|
|
|
grid-template-columns: repeat(2, auto);
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-27 22:10:32 +00:00
|
|
|
.game {
|
2022-10-27 02:38:30 +00:00
|
|
|
display: grid;
|
2022-10-31 04:08:33 +00:00
|
|
|
grid-template-columns: minmax(auto, 400px) 1fr;
|
2022-10-27 02:38:30 +00:00
|
|
|
gap: 2rem;
|
|
|
|
|
margin: 1rem;
|
2022-10-27 22:10:32 +00:00
|
|
|
place-items: center;
|
2022-10-27 03:07:43 +00:00
|
|
|
|
|
|
|
|
@media (max-width: 650px) {
|
|
|
|
|
grid-template-columns: 1fr;
|
2022-10-27 22:10:32 +00:00
|
|
|
place-items: center;
|
2022-10-27 03:07:43 +00:00
|
|
|
}
|
2022-10-27 02:38:30 +00:00
|
|
|
}
|
2022-07-11 04:17:59 +00:00
|
|
|
|
2022-10-27 02:38:30 +00:00
|
|
|
.details {
|
|
|
|
|
display: grid;
|
2022-10-31 00:56:21 +00:00
|
|
|
grid-template-columns: 1fr 1fr;
|
2022-10-27 02:38:30 +00:00
|
|
|
gap: 0.5rem;
|
2022-10-31 00:56:21 +00:00
|
|
|
place-content: center;
|
2022-10-27 02:38:30 +00:00
|
|
|
margin: 1rem;
|
|
|
|
|
a,
|
|
|
|
|
p {
|
|
|
|
|
margin: 1rem;
|
|
|
|
|
}
|
2022-10-27 03:07:43 +00:00
|
|
|
|
2022-10-31 04:08:33 +00:00
|
|
|
@media (max-width: 550px) {
|
2022-10-31 00:56:21 +00:00
|
|
|
grid-template-columns: 1fr;
|
2022-10-27 03:07:43 +00:00
|
|
|
}
|
2022-10-27 02:38:30 +00:00
|
|
|
}
|
2022-07-12 00:00:32 +00:00
|
|
|
|
2022-10-27 02:38:30 +00:00
|
|
|
.description {
|
|
|
|
|
display: grid;
|
2022-10-31 01:51:43 +00:00
|
|
|
place-items: center;
|
2022-10-27 02:38:30 +00:00
|
|
|
gap: 1.5rem;
|
|
|
|
|
margin: 1rem;
|
|
|
|
|
}
|
2022-09-01 05:17:11 +00:00
|
|
|
|
2022-10-31 15:25:02 +00:00
|
|
|
.overflow-description {
|
|
|
|
|
display: grid;
|
|
|
|
|
gap: 1.5rem;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-27 02:38:30 +00:00
|
|
|
.with-icon {
|
2022-10-31 15:25:02 +00:00
|
|
|
display: grid;
|
|
|
|
|
grid-template-columns: repeat(2, auto);
|
|
|
|
|
/* flex-wrap: wrap; */
|
2022-10-27 02:38:30 +00:00
|
|
|
place-items: center;
|
2022-10-31 04:08:33 +00:00
|
|
|
gap: 1rem;
|
2022-10-27 02:38:30 +00:00
|
|
|
}
|
2022-07-11 04:17:59 +00:00
|
|
|
</style>
|