fix JS error and incorrect comment thread for SHIFT+UP (#6574)

This commit is contained in:
Saturnino Abril
2017-06-05 23:09:43 +08:00
committed by Harrison Healey
parent b53ca57bad
commit b0f32e3c19
3 changed files with 15 additions and 10 deletions

View File

@@ -21,7 +21,7 @@ export default function CommentIcon(props) {
iconStyle = iconStyle + ' ' + props.searchStyle;
}
let commentIconId = props.idPrefix;
let commentIconId = props.channelId + props.idPrefix;
if (props.idCount > -1) {
commentIconId += props.idCount;
}
@@ -47,11 +47,13 @@ CommentIcon.propTypes = {
idCount: PropTypes.number,
handleCommentClick: PropTypes.func.isRequired,
searchStyle: PropTypes.string,
commentCount: PropTypes.number
commentCount: PropTypes.number,
channelId: PropTypes.string
};
CommentIcon.defaultProps = {
idCount: -1,
searchStyle: '',
commentCount: 0
commentCount: 0,
channelId: ''
};

View File

@@ -504,11 +504,12 @@ export default class CreatePost extends React.Component {
return;
}
const lastPostEl = document.getElementById(this.state.channelId + 'commentIcon0');
if (!e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey && e.keyCode === KeyCodes.UP && this.state.message === '') {
e.preventDefault();
const channelId = ChannelStore.getCurrentId();
const lastPost = PostStore.getCurrentUsersLatestPost(channelId);
const lastPost = PostStore.getCurrentUsersLatestPost(this.state.channelId);
if (!lastPost) {
return;
}
@@ -529,15 +530,15 @@ export default class CreatePost extends React.Component {
channelId: lastPost.channel_id,
comments: PostStore.getCommentCount(lastPost)
});
} else if (!e.ctrlKey && !e.metaKey && !e.altKey && e.shiftKey && e.keyCode === KeyCodes.UP && this.state.message === '') {
} else if (!e.ctrlKey && !e.metaKey && !e.altKey && e.shiftKey && e.keyCode === KeyCodes.UP && this.state.message === '' && lastPostEl) {
e.preventDefault();
if (document.createEvent) {
var evt = document.createEvent('MouseEvents');
const evt = document.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
document.getElementById('commentIcon0').dispatchEvent(evt);
lastPostEl.dispatchEvent(evt);
} else if (document.createEventObject) {
var evObj = document.createEventObject();
document.getElementById('commentIcon0').fireEvent('onclick', evObj);
const evObj = document.createEventObject();
lastPostEl.fireEvent('onclick', evObj);
}
}

View File

@@ -17,6 +17,7 @@ import Constants from 'utils/constants.jsx';
import DelayedAction from 'utils/delayed_action.jsx';
import {Overlay} from 'react-bootstrap';
import EmojiPicker from 'components/emoji_picker/emoji_picker.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import PropTypes from 'prop-types';
@@ -351,6 +352,7 @@ export default class PostInfo extends React.Component {
idCount={idCount}
handleCommentClick={this.props.handleCommentClick}
commentCount={this.props.commentCount}
channelId={ChannelStore.getCurrentId()}
/>
);