From 151c50f7aff62652be8a66c0b7c89a70193ae929 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Thu, 10 Oct 2024 16:27:00 +0530 Subject: [PATCH] Tune semantics --- web/packages/base/components/MiniDialog.tsx | 27 +++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/web/packages/base/components/MiniDialog.tsx b/web/packages/base/components/MiniDialog.tsx index 0efada4f47..91d8e78736 100644 --- a/web/packages/base/components/MiniDialog.tsx +++ b/web/packages/base/components/MiniDialog.tsx @@ -71,22 +71,17 @@ export interface MiniDialogAttributes { * is opened, allowing the user to confirm just by pressing ENTER. */ autoFocus?: boolean; - /** - * If `true`, close the dialog after {@link action} completes. - * TODO: Test/Impl/Is this needed? - */ - autoClose?: boolean; /** * The function to call when the user activates the button. * - * Default is to close the dialog. + * If this function returns a promise, then an activity indicator will + * be shown on the button until the promise settles. * - * It is passed a {@link setLoading} function that can be used to show - * or hide loading indicator or the primary action button. + * If this function is not provided, or if the function completes / + * fullfills, then then the dialog is automatically closed. Otherwise + * (that is, if the provided function throws), the dialog remains open. */ - action?: - | (() => void | Promise) - | ((setLoading: (value: boolean) => void) => void | Promise); + action?: () => void | Promise; }; /** * The string to use as the label for the cancel button. @@ -185,8 +180,14 @@ export const AttributedMiniDialog: React.FC< color={attributes.continue.color ?? "accent"} autoFocus={attributes.continue.autoFocus} onClick={async () => { - await attributes.continue?.action?.(setLoading); - onClose(); + setLoading(true); + try { + await attributes.continue?.action?.(); + setLoading(false); + onClose(); + } catch { + setLoading(false); + } }} > {attributes.continue.text ?? t("ok")}