From ed6b8d8b39a3985a059beb3574a61151d3db41d7 Mon Sep 17 00:00:00 2001 From: ZXY101 Date: Thu, 14 Sep 2023 12:19:25 +0200 Subject: [PATCH] Add confirmation popup util --- src/lib/components/Catalog.svelte | 8 ++++ src/lib/components/ConfirmationPopup.svelte | 25 +++++++++++ src/lib/components/Modal.svelte | 47 --------------------- src/lib/util/index.ts | 3 +- src/lib/util/modals.ts | 17 ++++++++ src/routes/+layout.svelte | 2 + src/routes/+page.svelte | 4 +- src/routes/[manga]/+page.svelte | 25 +++-------- 8 files changed, 63 insertions(+), 68 deletions(-) create mode 100644 src/lib/components/ConfirmationPopup.svelte delete mode 100644 src/lib/components/Modal.svelte create mode 100644 src/lib/util/modals.ts diff --git a/src/lib/components/Catalog.svelte b/src/lib/components/Catalog.svelte index b9c06bf..9ea0aad 100644 --- a/src/lib/components/Catalog.svelte +++ b/src/lib/components/Catalog.svelte @@ -1,10 +1,18 @@ {#if $catalog} {#if $catalog.length > 0} +
{#each $catalog as { manga }} diff --git a/src/lib/components/ConfirmationPopup.svelte b/src/lib/components/ConfirmationPopup.svelte new file mode 100644 index 0000000..16403cc --- /dev/null +++ b/src/lib/components/ConfirmationPopup.svelte @@ -0,0 +1,25 @@ + + + +
+ +

+ {$confirmationPopupStore?.message} +

+ + +
+
diff --git a/src/lib/components/Modal.svelte b/src/lib/components/Modal.svelte deleted file mode 100644 index 60d670a..0000000 --- a/src/lib/components/Modal.svelte +++ /dev/null @@ -1,47 +0,0 @@ - - - - -

- -

- -
- -
-
- - diff --git a/src/lib/util/index.ts b/src/lib/util/index.ts index 8b11aef..bcdab1e 100644 --- a/src/lib/util/index.ts +++ b/src/lib/util/index.ts @@ -1,3 +1,4 @@ export * from './snackbar' export * from './upload' -export * from './misc' \ No newline at end of file +export * from './misc' +export * from './modals' \ No newline at end of file diff --git a/src/lib/util/modals.ts b/src/lib/util/modals.ts new file mode 100644 index 0000000..6565055 --- /dev/null +++ b/src/lib/util/modals.ts @@ -0,0 +1,17 @@ +import { writable } from "svelte/store"; + +type ConfirmationPopup = { + open: boolean; + message: string; + onConfirm?: () => void; +}; +export const confirmationPopupStore = writable(undefined); + +export function promptConfirmation(message: string, onConfirm?: () => void) { + confirmationPopupStore.set({ + open: true, + message, + onConfirm + }); +} + diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 00a7bff..78263c8 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -3,10 +3,12 @@ import NavBar from '$lib/components/NavBar.svelte'; import Snackbar from '$lib/components/Snackbar.svelte'; import '../app.scss'; + import ConfirmationPopup from '$lib/components/ConfirmationPopup.svelte'; +
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index ab44104..3a89bc4 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -2,4 +2,6 @@ import Catalog from '$lib/components/Catalog.svelte'; -
+
+ +
diff --git a/src/routes/[manga]/+page.svelte b/src/routes/[manga]/+page.svelte index 4a9d65b..96fc94d 100644 --- a/src/routes/[manga]/+page.svelte +++ b/src/routes/[manga]/+page.svelte @@ -3,9 +3,9 @@ import { goto } from '$app/navigation'; import { onMount } from 'svelte'; import VolumeItem from '$lib/components/VolumeItem.svelte'; - import { Button, Modal } from 'flowbite-svelte'; - import { ExclamationCircleOutline } from 'flowbite-svelte-icons'; + import { Button } from 'flowbite-svelte'; import { db } from '$lib/catalog/db'; + import { promptConfirmation } from '$lib/util'; const manga = $currentManga?.sort((a, b) => { if (a.volumeName < b.volumeName) { @@ -17,23 +17,21 @@ return 0; }); - let popupModal = false; - onMount(() => { if (!manga) { goto('/'); } }); - function onDelete() { - popupModal = true; - } - async function confirmDelete() { const title = manga?.[0].mokuroData.title_uuid; await db.catalog.delete(title); goto('/'); } + + function onDelete() { + promptConfirmation('Are you sure you want to delete this manga?', confirmDelete); + }
@@ -49,17 +47,6 @@
- -
- -

- Are you sure you want to delete this manga? -

- - -
-
-