diff --git a/src/lib/client/confirm.svelte.ts b/src/lib/client/confirm.svelte.ts new file mode 100644 index 0000000..3fa1aef --- /dev/null +++ b/src/lib/client/confirm.svelte.ts @@ -0,0 +1,41 @@ +export type ConfirmOptions = { + title: string; + message?: string; + confirmLabel?: string; + cancelLabel?: string; + destructive?: boolean; +}; + +type PendingRequest = ConfirmOptions & { + resolve: (result: boolean) => void; +}; + +class ConfirmStore { + pending = $state(null); + + ask(options: ConfirmOptions): Promise { + // If another dialog is already open, close it as cancelled so we don't stack. + if (this.pending) this.pending.resolve(false); + return new Promise((resolve) => { + this.pending = { ...options, resolve }; + }); + } + + answer(result: boolean): void { + if (!this.pending) return; + const p = this.pending; + this.pending = null; + p.resolve(result); + } +} + +export const confirmStore = new ConfirmStore(); + +/** + * Show a modal confirmation dialog. Resolves to true on confirm, false on cancel/Escape. + * Safe on the server: falls back to the native confirm() only in the browser. + */ +export function confirmAction(options: ConfirmOptions): Promise { + if (typeof window === 'undefined') return Promise.resolve(false); + return confirmStore.ask(options); +} diff --git a/src/lib/components/ConfirmDialog.svelte b/src/lib/components/ConfirmDialog.svelte new file mode 100644 index 0000000..f9986d4 --- /dev/null +++ b/src/lib/components/ConfirmDialog.svelte @@ -0,0 +1,147 @@ + + +{#if confirmStore.pending} + {@const p = confirmStore.pending} + +{/if} + + diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 5284db5..eadd109 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -2,6 +2,7 @@ import { onMount } from 'svelte'; import { profileStore } from '$lib/client/profile.svelte'; import ProfileSwitcher from '$lib/components/ProfileSwitcher.svelte'; + import ConfirmDialog from '$lib/components/ConfirmDialog.svelte'; let { children } = $props(); @@ -10,6 +11,8 @@ }); + +
Kochwas
diff --git a/src/routes/admin/domains/+page.svelte b/src/routes/admin/domains/+page.svelte index c14c476..0b59c21 100644 --- a/src/routes/admin/domains/+page.svelte +++ b/src/routes/admin/domains/+page.svelte @@ -1,6 +1,7 @@