From 4f7c76c908bab51a810a991be44b7b7b375238eb Mon Sep 17 00:00:00 2001 From: Hendrik Date: Fri, 17 Apr 2026 17:23:07 +0200 Subject: [PATCH] feat(ui): custom dialog replaces all remaining window.alert() calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit alertAction({title, message}) returns Promise and renders the same ConfirmDialog with infoOnly:true — single OK button, no Abbrechen. Replaces: - 'Bitte Profil wählen.' (recipe rating / favorite / cooked / comment) - 'Bitte Profil wählen, um zu liken.' (wishlist) - 'Profil konnte nicht angelegt werden' (ProfileSwitcher) - 'Umbenennen fehlgeschlagen' (admin/profiles) - 'Speichern fehlgeschlagen' (preview) No window.alert() or window.confirm() left in the codebase. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/lib/client/confirm.svelte.ts | 13 +++++++++++++ src/lib/components/ConfirmDialog.svelte | 16 +++++++++------- src/lib/components/ProfileSwitcher.svelte | 6 +++++- src/routes/admin/profiles/+page.svelte | 7 +++++-- src/routes/preview/+page.svelte | 6 +++++- src/routes/recipes/[id]/+page.svelte | 22 +++++++++++++++++----- src/routes/wishlist/+page.svelte | 7 +++++-- 7 files changed, 59 insertions(+), 18 deletions(-) diff --git a/src/lib/client/confirm.svelte.ts b/src/lib/client/confirm.svelte.ts index 3fa1aef..368c3eb 100644 --- a/src/lib/client/confirm.svelte.ts +++ b/src/lib/client/confirm.svelte.ts @@ -4,6 +4,8 @@ export type ConfirmOptions = { confirmLabel?: string; cancelLabel?: string; destructive?: boolean; + /** If true, hide the cancel button — used for simple info/alert dialogs. */ + infoOnly?: boolean; }; type PendingRequest = ConfirmOptions & { @@ -39,3 +41,14 @@ export function confirmAction(options: ConfirmOptions): Promise { if (typeof window === 'undefined') return Promise.resolve(false); return confirmStore.ask(options); } + +/** + * Show a modal info dialog with a single OK button. Resolves when dismissed. + * Use instead of window.alert(). + */ +export function alertAction(options: Omit): Promise { + if (typeof window === 'undefined') return Promise.resolve(); + return confirmStore + .ask({ ...options, infoOnly: true, confirmLabel: options.confirmLabel ?? 'OK' }) + .then(() => undefined); +} diff --git a/src/lib/components/ConfirmDialog.svelte b/src/lib/components/ConfirmDialog.svelte index f9986d4..cd63486 100644 --- a/src/lib/components/ConfirmDialog.svelte +++ b/src/lib/components/ConfirmDialog.svelte @@ -41,13 +41,15 @@

{p.message}

{/if}
- + {#if !p.infoOnly} + + {/if}