boredgame/src/lib/components/game/index.svelte

105 lines
2.6 KiB
Svelte
Raw Normal View History

<script lang="ts">
import { fade } from 'svelte/transition';
2022-08-08 21:13:51 +00:00
import { MinusCircleIcon, PlusCircleIcon } from '@rgossiaux/svelte-heroicons/outline';
2022-08-09 23:27:42 +00:00
import type { GameType, SavedGameType } from '$lib/types';
import { collectionStore } from '$lib/stores/collectionStore';
2022-07-28 00:05:54 +00:00
import { addToCollection, removeFromCollection } from '$lib/util/manipulateCollection';
export let game: GameType | SavedGameType;
export let minimal: boolean = false;
2022-07-12 00:07:03 +00:00
export let detailed: boolean = false;
2022-08-08 21:13:51 +00:00
$: existsInCollection = $collectionStore.find((item: SavedGameType) => item.id === game.id);
</script>
<article class="game-container" transition:fade>
<div class="game-info">
<h2>{game.name}</h2>
<a class="thumbnail" href={`/game/${game.id}`}>
<img width="140" height="140" src={game.thumb_url} alt={`Image of ${game.name}`} />
</a>
</div>
2022-08-29 17:17:32 +00:00
{#if !minimal}
<div class="game-details">
<p>{game.year_published}</p>
<p>{game.players} {game.max_players === 1 ? 'player' : 'players'}</p>
<p>{game.playtime} minutes</p>
<p>Minimum Age: {game.min_age}</p>
<a href={`/game/${game.id}`}>View Game</a>
{#if detailed}
<div class="description">{@html game.description}</div>
{/if}
</div>
{/if}
{#if existsInCollection}
<button
aria-label="Remove from collection"
class="btn"
type="button"
on:click={() => removeFromCollection(game)}
>Remove <MinusCircleIcon width="24" height="24" /></button
2022-07-28 00:05:54 +00:00
>
{:else}
<button
aria-label="Add to collection"
class="btn"
type="button"
on:click={() => addToCollection(game)}
>Add to collection <PlusCircleIcon width="24" height="24" /></button
2022-07-28 00:05:54 +00:00
>
{/if}
</article>
<style lang="scss">
img {
border-radius: 10px;
}
button {
2022-08-08 21:13:51 +00:00
display: flex;
justify-content: space-between;
align-items: center;
2022-08-08 21:13:51 +00:00
gap: 1rem;
width: 100%;
border-radius: 10px;
padding: 1rem;
background-color: var(--color-btn-primary-active);
}
2022-08-08 21:13:51 +00:00
/* :global(.icon) {
width: 24px;
height: 24px;
} */
.game-container {
2022-07-26 02:04:05 +00:00
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;
border-radius: 8px;
background-color: var(--primary);
&:hover {
background-color: hsla(222, 9%, 65%, 1);
}
.game-info {
display: grid;
gap: 0.5rem;
2022-07-26 02:04:05 +00:00
margin: 0.2rem;
}
.game-details {
2022-07-28 00:05:54 +00:00
p,
a {
2022-07-26 02:04:05 +00:00
padding: 0.25rem;
}
}
}
</style>