Remove unnecessary Modal.createDialogWithElement, complete with its broken onFinished() support. Switch SetDisplayNameDialog to use Modal.createDialog(). Explicitly pass false to closeDialog if the user tries to cancel dialogs by clicking on the background, rather than passing in an event object which evaluates to true.

pull/21833/head
Matthew Hodgson 2016-03-18 11:15:06 +00:00
parent e63990a66e
commit deaa5c350a
2 changed files with 20 additions and 35 deletions

View File

@ -35,36 +35,13 @@ module.exports = {
return container; return container;
}, },
createDialogWithElement: function(element, props, className) {
var self = this;
var closeDialog = function() {
ReactDOM.unmountComponentAtNode(self.getOrCreateContainer());
if (props && props.onFinished) props.onFinished.apply(null, arguments);
};
var dialog = (
<div className={"mx_Dialog_wrapper " + className}>
<div className="mx_Dialog">
{element}
</div>
<div className="mx_Dialog_background" onClick={closeDialog}></div>
</div>
);
ReactDOM.render(dialog, this.getOrCreateContainer());
return {close: closeDialog};
},
createDialog: function (Element, props, className) { createDialog: function (Element, props, className) {
var self = this; var self = this;
// never call this via modal.close() from onFinished() otherwise it will loop
var closeDialog = function() { var closeDialog = function() {
ReactDOM.unmountComponentAtNode(self.getOrCreateContainer());
if (props && props.onFinished) props.onFinished.apply(null, arguments); if (props && props.onFinished) props.onFinished.apply(null, arguments);
ReactDOM.unmountComponentAtNode(self.getOrCreateContainer());
}; };
// FIXME: If a dialog uses getDefaultProps it clobbers the onFinished // FIXME: If a dialog uses getDefaultProps it clobbers the onFinished
@ -74,7 +51,7 @@ module.exports = {
<div className="mx_Dialog"> <div className="mx_Dialog">
<Element {...props} onFinished={closeDialog}/> <Element {...props} onFinished={closeDialog}/>
</div> </div>
<div className="mx_Dialog_background" onClick={closeDialog}></div> <div className="mx_Dialog_background" onClick={ closeDialog.bind(this, false) }></div>
</div> </div>
); );

View File

@ -522,16 +522,22 @@ module.exports = React.createClass({
var SetDisplayNameDialog = sdk.getComponent('views.dialogs.SetDisplayNameDialog'); var SetDisplayNameDialog = sdk.getComponent('views.dialogs.SetDisplayNameDialog');
var dialog_defer = q.defer(); var dialog_defer = q.defer();
var dialog_ref; var dialog_ref;
var modal; Modal.createDialog(SetDisplayNameDialog, {
var dialog_instance = <SetDisplayNameDialog currentDisplayName={result.displayname} ref={(r) => { currentDisplayName: result.displayname,
ref: (r) => {
dialog_ref = r; dialog_ref = r;
}} onFinished={() => { },
cli.setDisplayName(dialog_ref.getValue()).done(() => { onFinished: (submitted) => {
dialog_defer.resolve(); if (submitted) {
}); cli.setDisplayName(dialog_ref.getValue()).done(() => {
modal.close(); dialog_defer.resolve();
}} /> });
modal = Modal.createDialogWithElement(dialog_instance); }
else {
dialog_defer.reject();
}
}
});
return dialog_defer.promise; return dialog_defer.promise;
} }
}); });
@ -561,6 +567,8 @@ module.exports = React.createClass({
joining: false, joining: false,
joinError: error joinError: error
}); });
if (!error) return;
var msg = error.message ? error.message : JSON.stringify(error); var msg = error.message ? error.message : JSON.stringify(error);
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
Modal.createDialog(ErrorDialog, { Modal.createDialog(ErrorDialog, {