From 7a7912ef6decebfc712d8fd9503e65eb7a322e61 Mon Sep 17 00:00:00 2001 From: Zerebos Date: Wed, 21 Feb 2024 19:49:24 -0500 Subject: [PATCH] Add onClose for modals --- renderer/src/modules/api/ui.js | 1 + renderer/src/ui/modals.js | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/renderer/src/modules/api/ui.js b/renderer/src/modules/api/ui.js index 15332691..b4bac7b8 100644 --- a/renderer/src/modules/api/ui.js +++ b/renderer/src/modules/api/ui.js @@ -50,6 +50,7 @@ const UI = { * @param {string} [options.cancelText=Cancel] Text for the cancel button * @param {callable} [options.onConfirm=NOOP] Callback to occur when clicking the submit button * @param {callable} [options.onCancel=NOOP] Callback to occur when clicking the cancel button + * @param {callable} [options.onClose=NOOP] Callback to occur when exiting the modal * @returns {string} The key used for this modal. */ showConfirmationModal(title, content, options = {}) { diff --git a/renderer/src/ui/modals.js b/renderer/src/ui/modals.js index 157b2f62..d5e5a09f 100644 --- a/renderer/src/ui/modals.js +++ b/renderer/src/ui/modals.js @@ -157,6 +157,7 @@ export default class Modals { * @param {string} [options.cancelText=Cancel] - text for the cancel button * @param {callable} [options.onConfirm=NOOP] - callback to occur when clicking the submit button * @param {callable} [options.onCancel=NOOP] - callback to occur when clicking the cancel button + * @param {callable} [options.onClose=NOOP] - callback to occur when exiting the modal * @param {string} [options.key] - key used to identify the modal. If not provided, one is generated and returned * @returns {string} - the key used for this modal */ @@ -168,7 +169,7 @@ export default class Modals { if (content instanceof FormattableString) content = content.toString(); const emptyFunction = () => {}; - const {onConfirm = emptyFunction, onCancel = emptyFunction, confirmText = Strings.Modals.okay, cancelText = Strings.Modals.cancel, danger = false, key = undefined} = options; + const {onClose = emptyFunction, onConfirm = emptyFunction, onCancel = emptyFunction, confirmText = Strings.Modals.okay, cancelText = Strings.Modals.cancel, danger = false, key = undefined} = options; if (!this.ModalActions || !this.ConfirmationModal || !this.Markdown) { return this.default(title, content, [ @@ -181,6 +182,7 @@ export default class Modals { content = content.map(c => typeof(c) === "string" ? React.createElement(Markdown, null, c) : c); const modalKey = ModalActions.openModal(props => { + console.log(props); return React.createElement(ErrorBoundary, { onError: () => { setTimeout(() => { @@ -197,7 +199,8 @@ export default class Modals { confirmText: confirmText, cancelText: cancelText, onConfirm: onConfirm, - onCancel: onCancel + onCancel: onCancel, + onCloseCallback: () => {if (props?.transitionState === 1) onClose?.()} }, props), React.createElement(ErrorBoundary, {}, content))); }, {modalKey: key}); return modalKey;