From 8aa2fd3c2d08a2b2dcd3664272e056261fca82b2 Mon Sep 17 00:00:00 2001 From: Bradley Shellnut Date: Wed, 31 Aug 2022 16:50:45 -0500 Subject: [PATCH] Testing base dialog at layout level using svelte component. --- .../components/dialog/DefaultDialog.svelte | 67 +++++++++++++++ .../dialog/RemoveCollectionDialog.svelte | 82 +++++++++++++++++++ src/lib/stores/boredState.ts | 25 ++---- src/lib/types.ts | 9 ++ src/routes/+layout.svelte | 53 ++++++++++++ src/routes/collection/+page.svelte | 45 ++-------- 6 files changed, 228 insertions(+), 53 deletions(-) create mode 100644 src/lib/components/dialog/DefaultDialog.svelte create mode 100644 src/lib/components/dialog/RemoveCollectionDialog.svelte diff --git a/src/lib/components/dialog/DefaultDialog.svelte b/src/lib/components/dialog/DefaultDialog.svelte new file mode 100644 index 0000000..262cc03 --- /dev/null +++ b/src/lib/components/dialog/DefaultDialog.svelte @@ -0,0 +1,67 @@ + + + { + boredState.update((n) => ({ ...n, dialog: { ...n.dialog, isOpen: false } })); + }} + static +> +
+ +
+ Default Dialog + Dialog Description + + +
+
+ + diff --git a/src/lib/components/dialog/RemoveCollectionDialog.svelte b/src/lib/components/dialog/RemoveCollectionDialog.svelte new file mode 100644 index 0000000..234d62b --- /dev/null +++ b/src/lib/components/dialog/RemoveCollectionDialog.svelte @@ -0,0 +1,82 @@ + + + { + boredState.update((n) => ({ ...n, dialog: { isOpen: false } })); + }} + static +> +
+ +
+ Remove from collection + Are you sure you want to remove from your collection? + + +
+
+
+ + diff --git a/src/lib/stores/boredState.ts b/src/lib/stores/boredState.ts index 78f10d3..5824923 100644 --- a/src/lib/stores/boredState.ts +++ b/src/lib/stores/boredState.ts @@ -1,26 +1,19 @@ -import type { BoredStore } from '$lib/types'; +import type { BoredStore, Dialog } from '$lib/types'; import { writable } from 'svelte/store'; +import DefaultDialog from '../components/dialog/DefaultDialog.svelte'; // import { BoredStore } from '$lib/types'; // Custom store const state = () => { - const { subscribe, set, update } = writable({ loading: false }); - - // function remove(id: string) { - // update((store) => { - // const newStore = store.filter((item: GameType) => item.id !== id); - // return [...newStore]; - // }); - // } - - // function removeAll() { - // update(() => { - // return []; - // }); - // } + const initialDialog: Dialog = { + isOpen: false, + content: DefaultDialog + } + const initial = { loading: false, dialog: initialDialog } + const { subscribe, set, update } = writable(initial); function clear() { - set({ loading: false }); + set(initial); } return { subscribe, set, update, clear }; diff --git a/src/lib/types.ts b/src/lib/types.ts index 6944ee8..a4d83dc 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -1,5 +1,14 @@ +import type { SvelteComponent } from "svelte"; + +export type Dialog = { + isOpen: boolean; + content?: typeof SvelteComponent; + additionalData?: SavedGameType | GameType; +} + export type BoredStore = { loading: boolean; + dialog: Dialog; }; export enum ToastType { diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index d894f0b..d020db2 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,6 +1,7 @@ @@ -48,28 +41,6 @@ {/if} -{#if isOpen} -
-
- (isOpen = false)} static> -
- -
- Remove from collection - Are you sure you want to remove from your collection? - - -
-
-
-
-
-{/if}