mirror of https://github.com/vector-im/riot-web
make MessageComposerInput (new and old) warn on unload
new needs binding due to class this ref being softer couldn't do this nicely in MessageComposer/Input as isTyping wasn't propagated. Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>pull/21833/head
parent
19482d751d
commit
6685cbcb25
|
@ -93,6 +93,7 @@ export default class MessageComposerInput extends React.Component {
|
|||
this.onEscape = this.onEscape.bind(this);
|
||||
this.setDisplayedCompletion = this.setDisplayedCompletion.bind(this);
|
||||
this.onMarkdownToggleClicked = this.onMarkdownToggleClicked.bind(this);
|
||||
this.onPageUnload = this.onPageUnload.bind(this);
|
||||
|
||||
const isRichtextEnabled = UserSettingsStore.getSyncedSetting('MessageComposerInput.isRichTextEnabled', false);
|
||||
|
||||
|
@ -233,11 +234,13 @@ export default class MessageComposerInput extends React.Component {
|
|||
this.refs.editor,
|
||||
this.props.room.roomId
|
||||
);
|
||||
window.addEventListener('beforeunload', this.onPageUnload);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
dis.unregister(this.dispatcherRef);
|
||||
this.sentHistory.saveLastTextEntry();
|
||||
window.removeEventListener('beforeunload', this.onPageUnload);
|
||||
}
|
||||
|
||||
componentWillUpdate(nextProps, nextState) {
|
||||
|
@ -249,6 +252,13 @@ export default class MessageComposerInput extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
onPageUnload(event) {
|
||||
if (this.isTyping) {
|
||||
return event.returnValue =
|
||||
'You seem to be typing a message, are you sure you want to quit?';
|
||||
}
|
||||
}
|
||||
|
||||
onAction(payload) {
|
||||
let editor = this.refs.editor;
|
||||
let contentState = this.state.editorState.getCurrentContent();
|
||||
|
|
|
@ -177,11 +177,20 @@ export default React.createClass({
|
|||
if (this.props.tabComplete) {
|
||||
this.props.tabComplete.setTextArea(this.refs.textarea);
|
||||
}
|
||||
window.addEventListener('beforeunload', this.onPageUnload);
|
||||
},
|
||||
|
||||
componentWillUnmount: function() {
|
||||
dis.unregister(this.dispatcherRef);
|
||||
this.sentHistory.saveLastTextEntry();
|
||||
window.removeEventListener('beforeunload', this.onPageUnload);
|
||||
},
|
||||
|
||||
onPageUnload(event) {
|
||||
if (this.isTyping) {
|
||||
return event.returnValue =
|
||||
'You seem to be typing a message, are you sure you want to quit?';
|
||||
}
|
||||
},
|
||||
|
||||
onAction: function(payload) {
|
||||
|
|
Loading…
Reference in New Issue