Adding dialog overlay to layout css, removing commented css, and updating dialog store on game page remove button click.

This commit is contained in:
Bradley Shellnut 2022-08-31 21:32:30 -05:00
parent 26d5b28323
commit 207c93da28
4 changed files with 30 additions and 140 deletions

View file

@ -148,4 +148,12 @@
padding: 40px 0; padding: 40px 0;
} }
} }
:global(.dialog-overlay) {
position: fixed;
inset: 0;
z-index: 100;
background-color: rgb(0 0 0);
opacity: 0.8;
}
</style> </style>

View file

@ -1,19 +1,12 @@
<script lang="ts"> <script lang="ts">
import { fade } from 'svelte/transition'; import type { GameType, SavedGameType } from '$root/lib/types';
import { import { gameStore } from '$lib/stores/gameSearchStore';
Dialog, import { boredState } from '$root/lib/stores/boredState';
DialogDescription, import RemoveCollectionDialog from '$root/lib/components/dialog/RemoveCollectionDialog.svelte';
DialogOverlay,
DialogTitle
} from '@rgossiaux/svelte-headlessui';
import Game from '$lib/components/game/index.svelte'; import Game from '$lib/components/game/index.svelte';
import TextSearch from '$lib/components/search/textSearch/index.svelte'; import TextSearch from '$lib/components/search/textSearch/index.svelte';
import RandomSearch from '$lib/components/search/random/index.svelte'; import RandomSearch from '$lib/components/search/random/index.svelte';
import Random from '$lib/components/random/index.svelte'; import Random from '$lib/components/random/index.svelte';
import { gameStore } from '$lib/stores/gameSearchStore';
import { boredState } from '$root/lib/stores/boredState';
import { removeFromCollection } from '$root/lib/util/manipulateCollection';
import type { GameType, SavedGameType } from '$root/lib/types';
async function handleSearch(event: SubmitEvent) { async function handleSearch(event: SubmitEvent) {
boredState.update((n) => ({ ...n, loading: true })); boredState.update((n) => ({ ...n, loading: true }));
@ -41,17 +34,15 @@
function handleRemoveGame(event: RemoveGameEvent) { function handleRemoveGame(event: RemoveGameEvent) {
console.log('event', event); console.log('event', event);
gameToRemove = event?.detail; gameToRemove = event?.detail;
isOpen = true; boredState.update((n) => ({
} ...n,
dialog: { isOpen: true, content: RemoveCollectionDialog, additionalData: gameToRemove }
function removeGame() { }));
removeFromCollection(gameToRemove);
isOpen = false;
} }
</script> </script>
<svelte:head> <svelte:head>
<title>Bored Game</title> <title>Bored Game | Home</title>
</svelte:head> </svelte:head>
<h1>Search Boardgames!</h1> <h1>Search Boardgames!</h1>
@ -76,28 +67,6 @@
</div> </div>
</div> </div>
{/if} {/if}
{#if isOpen}
<div class="container">
<div transition:fade>
<Dialog open={isOpen} on:close={() => (isOpen = false)} static>
<div transition:fade>
<DialogOverlay class="dialog-overlay" />
<div class="dialog">
<DialogTitle>Remove from collection</DialogTitle>
<DialogDescription
>Are you sure you want to remove from your collection?</DialogDescription
>
<div class="dialog-footer">
<button on:click={() => removeGame()}>Remove</button>
<button on:click={() => (isOpen = false)}>Cancel</button>
</div>
</div>
</div>
</Dialog>
</div>
</div>
{/if}
<style lang="scss"> <style lang="scss">
.games { .games {
@ -132,47 +101,4 @@
grid-template-columns: 1fr 1fr; grid-template-columns: 1fr 1fr;
} }
} }
.dialog {
display: grid;
gap: 1.5rem;
position: absolute;
top: 35%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 101;
border-radius: 10px;
background-color: var(--clr-input-bg);
padding: 2rem;
min-width: 400px;
.dialog-footer {
display: flex;
justify-content: space-between;
gap: 2rem;
margin: 1rem 0;
button {
display: flex;
place-content: center;
gap: 1rem;
width: 100%;
border-radius: 10px;
padding: 1rem;
background-color: var(--color-btn-primary-active);
&:hover {
background-color: var(--color-btn-primary-active-hover);
}
}
}
}
:global(.dialog-overlay) {
position: fixed;
inset: 0;
z-index: 100;
background-color: rgb(0 0 0);
opacity: 0.8;
}
</style> </style>

View file

@ -64,54 +64,4 @@
grid-template-columns: 1fr; grid-template-columns: 1fr;
} }
} }
/* .dialog {
display: grid;
gap: 1.5rem;
position: absolute;
top: 35%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 101;
border-radius: 10px;
background-color: var(--clr-input-bg);
padding: 2rem;
min-width: 400px;
.dialog-footer {
display: flex;
justify-content: space-between;
gap: 2rem;
margin: 1rem 0;
button {
display: flex;
place-content: center;
gap: 1rem;
width: 100%;
border-radius: 10px;
padding: 1rem;
background-color: var(--color-btn-primary-active);
&:hover {
background-color: var(--color-btn-primary-active-hover);
}
}
}
}
:global(.dialog-overlay) {
position: fixed;
inset: 0;
z-index: 100;
background-color: rgb(0 0 0);
opacity: 0.8;
} */
/*
.container > .button {
display: grid;
justify-content: center;
background-color: var(--primary);
} */
</style> </style>

View file

@ -1,8 +1,4 @@
<script lang="ts"> <script lang="ts">
// throw new Error(
// '@migration task: Add data prop (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292707)'
// );
import { fade } from 'svelte/transition'; import { fade } from 'svelte/transition';
import { import {
ExternalLinkIcon, ExternalLinkIcon,
@ -11,12 +7,15 @@
PlusCircleIcon, PlusCircleIcon,
PlusIcon PlusIcon
} from '@rgossiaux/svelte-heroicons/outline'; } from '@rgossiaux/svelte-heroicons/outline';
import { collectionStore } from '$lib/stores/collectionStore';
import type { GameType, SavedGameType } from '$lib/types'; import type { GameType, SavedGameType } from '$lib/types';
import { addToCollection, removeFromCollection } from '$lib/util/manipulateCollection'; 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 type { PageData } from './$types';
import { boredState } from '$root/lib/stores/boredState';
$: existsInCollection = $collectionStore.find((item: SavedGameType) => item.id === game.id); $: existsInCollection = $collectionStore.find((item: SavedGameType) => item.id === game.id);
export let data: PageData; export let data: PageData;
export let game: GameType = data?.game; export let game: GameType = data?.game;
console.log('page game', game); console.log('page game', game);
@ -29,6 +28,13 @@
firstParagraphEnd = game?.description?.indexOf('</ p>') + 5; firstParagraphEnd = game?.description?.indexOf('</ p>') + 5;
} }
console.log('firstParagraphEnd', firstParagraphEnd); console.log('firstParagraphEnd', firstParagraphEnd);
function removeGame() {
boredState.update((n) => ({
...n,
dialog: { isOpen: true, content: RemoveCollectionDialog, additionalData: game }
}));
}
</script> </script>
<svelte:head> <svelte:head>
@ -59,7 +65,7 @@
>Board Game Atlas Link <ExternalLinkIcon width="24" height="24" /></a >Board Game Atlas Link <ExternalLinkIcon width="24" height="24" /></a
> >
{#if existsInCollection} {#if existsInCollection}
<button class="btn" type="button" on:click={() => removeFromCollection(game)} <button class="btn" type="button" on:click={() => removeGame()}
>Remove from collection <MinusCircleIcon width="24" height="24" /></button >Remove from collection <MinusCircleIcon width="24" height="24" /></button
> >
{:else} {:else}