[PLT-2802] Memory leaks in file upload shortcuts (#2889)
* Added file upload shortcuts (CTRL+U and CMD+U) * Added KeyCode for U * Preventing memory leaks
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
f2e788f4b1
Коммит
e898686301
@@ -129,9 +129,7 @@ class FileUpload extends React.Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
var inputDiv = ReactDOM.findDOMNode(this.refs.input);
|
||||
var self = this;
|
||||
const {formatMessage} = this.props.intl;
|
||||
|
||||
if (this.props.postType === 'post') {
|
||||
$('.row.main').dragster({
|
||||
@@ -177,7 +175,29 @@ class FileUpload extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('paste', (e) => {
|
||||
document.addEventListener('paste', this.pasteUpload);
|
||||
document.addEventListener('keydown', this.keyUpload);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
let target;
|
||||
if (this.props.postType === 'post') {
|
||||
target = $('.row.main');
|
||||
} else {
|
||||
target = $('.post-right__container');
|
||||
}
|
||||
|
||||
document.removeEventListener('paste', this.pasteUpload);
|
||||
document.removeEventListener('keydown', this.keyUpload);
|
||||
|
||||
// jquery-dragster doesn't provide a function to unregister itself so do it manually
|
||||
target.off('dragenter dragleave dragover drop dragster:enter dragster:leave dragster:over dragster:drop');
|
||||
}
|
||||
|
||||
pasteUpload(e) {
|
||||
var inputDiv = ReactDOM.findDOMNode(this.refs.input);
|
||||
const {formatMessage} = this.props.intl;
|
||||
|
||||
if (!e.clipboardData) {
|
||||
return;
|
||||
}
|
||||
@@ -222,7 +242,6 @@ class FileUpload extends React.Component {
|
||||
if (Constants.IMAGE_TYPES.indexOf(ext) < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var channelId = self.props.channelId || ChannelStore.getCurrentId();
|
||||
|
||||
// generate a unique id that can be used by other components to refer back to this file upload
|
||||
@@ -260,26 +279,12 @@ class FileUpload extends React.Component {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', (e) => {
|
||||
//CTRL+U or CMD+U for file uploads
|
||||
keyUpload(e) {
|
||||
if ((e.ctrlKey || e.metaKey) && e.keyCode === Constants.KeyCodes.U) {
|
||||
$(this.refs.input).focus().trigger('click');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
let target;
|
||||
if (this.props.postType === 'post') {
|
||||
target = $('.row.main');
|
||||
} else {
|
||||
target = $('.post-right__container');
|
||||
}
|
||||
|
||||
// jquery-dragster doesn't provide a function to unregister itself so do it manually
|
||||
target.off('dragenter dragleave dragover drop dragster:enter dragster:leave dragster:over dragster:drop');
|
||||
}
|
||||
|
||||
cancelUpload(clientId) {
|
||||
|
||||
Ссылка в новой задаче
Block a user