diff --git a/src/lib/components/functional/Dialog.svelte b/src/lib/components/functional/Dialog.svelte new file mode 100644 index 0000000..230165b --- /dev/null +++ b/src/lib/components/functional/Dialog.svelte @@ -0,0 +1,82 @@ + + +
+
+
+
+ +
+

{title}

+
+
+
+

{message}

+
+
+ {#each buttons as { text, action }, i} + + {/each} +
+
diff --git a/src/lib/components/layout/Dialogs.svelte b/src/lib/components/layout/Dialogs.svelte new file mode 100644 index 0000000..d2b0446 --- /dev/null +++ b/src/lib/components/layout/Dialogs.svelte @@ -0,0 +1,35 @@ + + +{#if dialogList.length > 0} +
+ {#each dialogList as { id, title, message, buttons, type }, i} + {#if i === 0} + + {/if} + {/each} +
+{/if} diff --git a/src/lib/components/layout/index.ts b/src/lib/components/layout/index.ts index ae17efc..e3c43d5 100644 --- a/src/lib/components/layout/index.ts +++ b/src/lib/components/layout/index.ts @@ -1,5 +1,6 @@ export { default as UploadRegion } from './UploadRegion.svelte'; export { default as Gradients } from './Gradients.svelte'; +export { default as Dialogs } from './Dialogs.svelte'; export { default as PageContent } from './PageContent.svelte'; export { default as MobileLogo } from './MobileLogo.svelte'; export { default as Footer } from './Footer.svelte'; \ No newline at end of file diff --git a/src/lib/store/DialogProvider.ts b/src/lib/store/DialogProvider.ts new file mode 100644 index 0000000..a66934d --- /dev/null +++ b/src/lib/store/DialogProvider.ts @@ -0,0 +1,46 @@ +import { writable } from "svelte/store"; + +type DialogType = "success" | "error" | "info" | "warning"; + +export interface Dialog { + id: number; + title: string; + message: string; + buttons: { + text: string; + action: () => void; + }[]; + type: DialogType; +} + +const dialogs = writable([]); + +let dialogId = 0; + +function addDialog( + title: string, + message: string, + buttons: Dialog["buttons"], + type: DialogType, +) { + const id = dialogId++; + + const newDialog: Dialog = { + id, + title, + message, + buttons, + type, + }; + dialogs.update((currentDialogs) => [...currentDialogs, newDialog]); + + return id; +} + +function removeDialog(id: number) { + dialogs.update((currentDialogs) => + currentDialogs.filter((dialog) => dialog.id !== id), + ); +} + +export { dialogs, addDialog, removeDialog }; diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 67d9aa9..adcb611 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -122,6 +122,8 @@ {/each} + +
diff --git a/src/routes/settings/+page.svelte b/src/routes/settings/+page.svelte index 6419056..6581dd2 100644 --- a/src/routes/settings/+page.svelte +++ b/src/routes/settings/+page.svelte @@ -2,6 +2,7 @@ import { browser } from "$app/environment"; import { log } from "$lib/logger"; import * as Settings from "$lib/sections/settings/index.svelte"; + import { addDialog, removeDialog } from "$lib/store/DialogProvider"; import { addToast } from "$lib/store/ToastProvider"; import { SettingsIcon } from "lucide-svelte"; import { onMount } from "svelte"; @@ -61,6 +62,38 @@
+