From d7f29179ea325fa78efa828cef90f74d06ef40d8 Mon Sep 17 00:00:00 2001 From: Chang Wei Date: Sat, 20 Aug 2022 03:26:01 +0800 Subject: [PATCH 1/6] fix: fix typo variable name from 'orginPress' to 'originPress' --- components/modal/AlertContainer.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/modal/AlertContainer.tsx b/components/modal/AlertContainer.tsx index f3e110c4..6f4c9d37 100644 --- a/components/modal/AlertContainer.tsx +++ b/components/modal/AlertContainer.tsx @@ -48,9 +48,9 @@ export default class AlertContainer extends React.Component< const { title, actions, content, onAnimationEnd } = this.props const footer = actions.map((button) => { // tslint:disable-next-line:only-arrow-functions - const orginPress = button.onPress || function () {} + const originPress = button.onPress || function () {} button.onPress = () => { - const res = orginPress() + const res = originPress() if (res && res.then) { res.then(() => { this.onClose() From 55026cb51cf466db93218c716e5127d962848320 Mon Sep 17 00:00:00 2001 From: Chang Wei Date: Sat, 20 Aug 2022 03:42:36 +0800 Subject: [PATCH 2/6] fix: add 'disabled' style to button's style list --- components/modal/Modal.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/components/modal/Modal.tsx b/components/modal/Modal.tsx index 77fe4f9a..bc621fce 100644 --- a/components/modal/Modal.tsx +++ b/components/modal/Modal.tsx @@ -105,6 +105,7 @@ class AntmModal extends React.Component { cancel: { color: '#000' }, default: {}, destructive: { color: 'red' }, + disabled: { color: 'lightgray' }, } buttonStyle = styleMap[buttonStyle] || {} } From d7a97d1bee67d121d34b1512fd9c9b582de6687a Mon Sep 17 00:00:00 2001 From: Chang Wei Date: Sat, 20 Aug 2022 03:45:37 +0800 Subject: [PATCH 3/6] fix: disable modal ok button before press handler promise becomes to resolve state --- components/modal/AlertContainer.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/components/modal/AlertContainer.tsx b/components/modal/AlertContainer.tsx index 6f4c9d37..2dd0737d 100644 --- a/components/modal/AlertContainer.tsx +++ b/components/modal/AlertContainer.tsx @@ -49,15 +49,15 @@ export default class AlertContainer extends React.Component< const footer = actions.map((button) => { // tslint:disable-next-line:only-arrow-functions const originPress = button.onPress || function () {} - button.onPress = () => { - const res = originPress() - if (res && res.then) { - res.then(() => { - this.onClose() - }) - } else { - this.onClose() + const originStyle = button.style + button.onPress = async () => { + if (button.style === 'disabled') { + return } + button.style = 'disabled' + await originPress() + button.style = originStyle + this.onClose() } return button }) From 847fff61f5ed60aae2653f8426bb49ed21fbc4dc Mon Sep 17 00:00:00 2001 From: Chang Wei Date: Sat, 20 Aug 2022 04:00:26 +0800 Subject: [PATCH 4/6] fix: fix type checking logic --- components/modal/Modal.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/modal/Modal.tsx b/components/modal/Modal.tsx index bc621fce..a0b1fdd6 100644 --- a/components/modal/Modal.tsx +++ b/components/modal/Modal.tsx @@ -98,7 +98,7 @@ class AntmModal extends React.Component { } if (button.style) { buttonStyle = button.style - if (typeof buttonStyle === 'string') { + if (typeof button.style === 'string') { const styleMap: { [key: string]: object } = { @@ -107,7 +107,7 @@ class AntmModal extends React.Component { destructive: { color: 'red' }, disabled: { color: 'lightgray' }, } - buttonStyle = styleMap[buttonStyle] || {} + buttonStyle = styleMap[button.style] || {} } } const noneBorder = From 6f7837b923ca23197db8d7c91e1a3a5b01153bd6 Mon Sep 17 00:00:00 2001 From: Chang Wei Date: Sat, 27 Aug 2022 12:33:23 +0800 Subject: [PATCH 5/6] fix: use `??` instead of `||` for setting the default value of originPress --- components/modal/AlertContainer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/modal/AlertContainer.tsx b/components/modal/AlertContainer.tsx index 2dd0737d..fcc1f45e 100644 --- a/components/modal/AlertContainer.tsx +++ b/components/modal/AlertContainer.tsx @@ -48,7 +48,7 @@ export default class AlertContainer extends React.Component< const { title, actions, content, onAnimationEnd } = this.props const footer = actions.map((button) => { // tslint:disable-next-line:only-arrow-functions - const originPress = button.onPress || function () {} + const originPress = button.onPress ?? function () {} const originStyle = button.style button.onPress = async () => { if (button.style === 'disabled') { From a4310145c7a7d4ef4ce219e2b7f538b57f87ef91 Mon Sep 17 00:00:00 2001 From: Chang Wei Date: Sat, 27 Aug 2022 13:01:54 +0800 Subject: [PATCH 6/6] fix: catch the error from originPress(), in finally, restore the button.style and call this.onClose() --- components/modal/AlertContainer.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/components/modal/AlertContainer.tsx b/components/modal/AlertContainer.tsx index fcc1f45e..b0cd7c68 100644 --- a/components/modal/AlertContainer.tsx +++ b/components/modal/AlertContainer.tsx @@ -55,9 +55,14 @@ export default class AlertContainer extends React.Component< return } button.style = 'disabled' - await originPress() - button.style = originStyle - this.onClose() + // developer should handle the errors by themselves, + // so we don't need to do anything at here + try { + await originPress() + } finally { + button.style = originStyle + this.onClose() + } } return button })