You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-08-04 23:02:14 +03:00
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>
This commit is contained in:
@@ -93,6 +93,7 @@ export default class MessageComposerInput extends React.Component {
|
|||||||
this.onEscape = this.onEscape.bind(this);
|
this.onEscape = this.onEscape.bind(this);
|
||||||
this.setDisplayedCompletion = this.setDisplayedCompletion.bind(this);
|
this.setDisplayedCompletion = this.setDisplayedCompletion.bind(this);
|
||||||
this.onMarkdownToggleClicked = this.onMarkdownToggleClicked.bind(this);
|
this.onMarkdownToggleClicked = this.onMarkdownToggleClicked.bind(this);
|
||||||
|
this.onPageUnload = this.onPageUnload.bind(this);
|
||||||
|
|
||||||
const isRichtextEnabled = UserSettingsStore.getSyncedSetting('MessageComposerInput.isRichTextEnabled', false);
|
const isRichtextEnabled = UserSettingsStore.getSyncedSetting('MessageComposerInput.isRichTextEnabled', false);
|
||||||
|
|
||||||
@@ -233,11 +234,13 @@ export default class MessageComposerInput extends React.Component {
|
|||||||
this.refs.editor,
|
this.refs.editor,
|
||||||
this.props.room.roomId
|
this.props.room.roomId
|
||||||
);
|
);
|
||||||
|
window.addEventListener('beforeunload', this.onPageUnload);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
dis.unregister(this.dispatcherRef);
|
dis.unregister(this.dispatcherRef);
|
||||||
this.sentHistory.saveLastTextEntry();
|
this.sentHistory.saveLastTextEntry();
|
||||||
|
window.removeEventListener('beforeunload', this.onPageUnload);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUpdate(nextProps, nextState) {
|
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) {
|
onAction(payload) {
|
||||||
let editor = this.refs.editor;
|
let editor = this.refs.editor;
|
||||||
let contentState = this.state.editorState.getCurrentContent();
|
let contentState = this.state.editorState.getCurrentContent();
|
||||||
|
@@ -177,11 +177,20 @@ export default React.createClass({
|
|||||||
if (this.props.tabComplete) {
|
if (this.props.tabComplete) {
|
||||||
this.props.tabComplete.setTextArea(this.refs.textarea);
|
this.props.tabComplete.setTextArea(this.refs.textarea);
|
||||||
}
|
}
|
||||||
|
window.addEventListener('beforeunload', this.onPageUnload);
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
dis.unregister(this.dispatcherRef);
|
dis.unregister(this.dispatcherRef);
|
||||||
this.sentHistory.saveLastTextEntry();
|
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) {
|
onAction: function(payload) {
|
||||||
|
Reference in New Issue
Block a user