Page MenuHomePhabricator

D3783.id11810.diff
No OneTemporary

D3783.id11810.diff

diff --git a/web/modals/threads/thread-settings-modal.react.js b/web/modals/threads/thread-settings-modal.react.js
--- a/web/modals/threads/thread-settings-modal.react.js
+++ b/web/modals/threads/thread-settings-modal.react.js
@@ -101,6 +101,7 @@
+onChangeThreadType: (event: SyntheticEvent<HTMLInputElement>) => void,
+onChangeAccountPassword: (event: SyntheticEvent<HTMLInputElement>) => void,
+hasPermissionForTab: (thread: ThreadInfo, tab: TabType) => boolean,
+ +deleteThreadAction: () => Promise<LeaveThreadPayload>,
};
class ThreadSettingsModal extends React.PureComponent<Props> {
nameInput: ?HTMLInputElement;
@@ -316,30 +317,9 @@
event.preventDefault();
this.props.dispatchActionPromise(
deleteThreadActionTypes,
- this.deleteThreadAction(),
+ this.props.deleteThreadAction(),
);
};
-
- async deleteThreadAction() {
- try {
- const response = await this.props.deleteThread(
- this.props.threadInfo.id,
- this.props.accountPassword,
- );
- this.props.onClose();
- return response;
- } catch (e) {
- const errorMessage =
- e.message === 'invalid_credentials'
- ? 'wrong password'
- : 'unknown error';
- this.props.setErrorMessage(errorMessage);
- this.props.setAccountPassword('');
- invariant(this.accountPasswordInput, 'accountPasswordInput ref unset');
- this.accountPasswordInput.focus();
- throw e;
- }
- }
}
const deleteThreadLoadingStatusSelector = createLoadingStatusSelector(
@@ -473,6 +453,25 @@
[],
);
+ const deleteThreadAction = React.useCallback(async () => {
+ invariant(threadInfo, 'threadInfo should exist in deleteThreadAction');
+ try {
+ const response = await callDeleteThread(threadInfo.id, accountPassword);
+ modalContext.clearModal();
+ return response;
+ } catch (e) {
+ setErrorMessage(
+ e.message === 'invalid_credentials'
+ ? 'wrong password'
+ : 'unknown error',
+ );
+ setAccountPassword('');
+ // TODO: accountPasswordInput.focus()
+ // (once ref is moved up to functional component)
+ throw e;
+ }
+ }, [accountPassword, callDeleteThread, modalContext, threadInfo]);
+
if (!threadInfo) {
return (
<Modal onClose={modalContext.clearModal} name="Invalid thread">
@@ -510,6 +509,7 @@
onChangeThreadType={onChangeThreadType}
onChangeAccountPassword={onChangeAccountPassword}
hasPermissionForTab={hasPermissionForTab}
+ deleteThreadAction={deleteThreadAction}
/>
);
},

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 8, 5:35 PM (21 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2443784
Default Alt Text
D3783.id11810.diff (2 KB)

Event Timeline