diff --git a/src/lib/components/game/index.svelte b/src/lib/components/game/index.svelte index 71aacaf..3bd90b1 100644 --- a/src/lib/components/game/index.svelte +++ b/src/lib/components/game/index.svelte @@ -1,4 +1,5 @@ @@ -36,8 +44,7 @@ aria-label="Remove from collection" class="btn" type="button" - on:click={() => removeFromCollection(game)} - >Remove removeGame()}>Remove {:else} 0) { - boredState.set({ loading: true, dialogOpen: false }); + boredState.set({ loading: true }); let randomNumber: number = Math.round(Math.random() * $collectionStore.length - 1); if ($collectionStore.at(randomNumber)) { gameStore.removeAll(); @@ -19,11 +19,11 @@ const responseData = await response.json(); console.log('responseData', responseData); gameStore.add(responseData?.game); - boredState.set({ loading: false, dialogOpen: false }); + boredState.set({ loading: false }); } else { toast.send('Error!', { duration: 3000, type: ToastType.ERROR, dismissible: true }); } - boredState.set({ loading: false, dialogOpen: false }); + boredState.set({ loading: false }); } else { toast.send('No items in your collection!', { duration: 3000, diff --git a/src/lib/components/search/random/index.svelte b/src/lib/components/search/random/index.svelte index 4c49dba..e0fc8a3 100644 --- a/src/lib/components/search/random/index.svelte +++ b/src/lib/components/search/random/index.svelte @@ -4,7 +4,7 @@ async function handleSubmit(event: SubmitEvent) { // submitting = true; - boredState.set({ loading: true, dialogOpen: false }); + boredState.set({ loading: true }); const form = event.target as HTMLFormElement; console.log('form', form); const response = await fetch('/api/games', { @@ -14,7 +14,7 @@ }); const responseData = await response.json(); // submitting = false; - boredState.set({ loading: false, dialogOpen: false }); + boredState.set({ loading: false }); gameStore.removeAll(); gameStore.addAll(responseData?.games); // games = responseData?.games; diff --git a/src/lib/stores/boredState.ts b/src/lib/stores/boredState.ts index 046f2a1..78f10d3 100644 --- a/src/lib/stores/boredState.ts +++ b/src/lib/stores/boredState.ts @@ -4,7 +4,7 @@ import { writable } from 'svelte/store'; // Custom store const state = () => { - const { subscribe, set, update } = writable({ loading: false, dialogOpen: false }); + const { subscribe, set, update } = writable({ loading: false }); // function remove(id: string) { // update((store) => { @@ -20,7 +20,7 @@ const state = () => { // } function clear() { - set({ loading: false, dialogOpen: false }); + set({ loading: false }); } return { subscribe, set, update, clear }; diff --git a/src/lib/types.ts b/src/lib/types.ts index 3c34514..6944ee8 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -1,6 +1,5 @@ export type BoredStore = { loading: boolean; - dialogOpen: boolean; }; export enum ToastType { diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 914f023..1ef1433 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,15 +1,8 @@ @@ -11,11 +35,37 @@ - {#each $collectionStore as game} - - {/each} + {#if $collectionStore.length === 0} + No games in your collection + {:else} + {#each $collectionStore as game} + + {/each} + {/if} +{#if isOpen} + + + (isOpen = false)} static> + + + + Remove from collection + Are you sure you want to remove from your collection? + + + + + + + +{/if}