diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2015-09-23 15:04:45 -0400 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2015-09-23 15:04:45 -0400 |
commit | bff0956ba57bb34a31ddfe4e60b6bdbc4253f3f5 (patch) | |
tree | ed17482fb10dd7245aefa3f512568f5c41a0beca /web | |
parent | 15f15de8ca5ee91e5d11ed017ba0e3d49b1471ec (diff) | |
parent | 845229d9836412c2592fdcd9da0e7b1b9fc76a15 (diff) | |
download | chat-bff0956ba57bb34a31ddfe4e60b6bdbc4253f3f5.tar.gz chat-bff0956ba57bb34a31ddfe4e60b6bdbc4253f3f5.tar.bz2 chat-bff0956ba57bb34a31ddfe4e60b6bdbc4253f3f5.zip |
Merge pull request #761 from mattermost/plt-356
PLT-356 Fix post not rendering properly in some cases.
Diffstat (limited to 'web')
-rw-r--r-- | web/react/components/post.jsx | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/web/react/components/post.jsx b/web/react/components/post.jsx index d3c6befd0..9127f00de 100644 --- a/web/react/components/post.jsx +++ b/web/react/components/post.jsx @@ -51,7 +51,7 @@ export default class Post extends React.Component { var post = this.props.post; client.createPost(post, post.channel_id, - function success(data) { + (data) => { AsyncClient.getPosts(); var channel = ChannelStore.get(post.channel_id); @@ -65,11 +65,11 @@ export default class Post extends React.Component { post: data }); }, - function error() { + () => { post.state = Constants.POST_FAILED; PostStore.updatePendingPost(post); this.forceUpdate(); - }.bind(this) + } ); post.state = Constants.POST_LOADING; @@ -81,31 +81,52 @@ export default class Post extends React.Component { return true; } - return false; - } - render() { - var post = this.props.post; - var parentPost = this.props.parentPost; - var posts = this.props.posts; + if (nextProps.sameRoot !== this.props.sameRoot) { + return true; + } - var type = 'Post'; - if (post.root_id && post.root_id.length > 0) { - type = 'Comment'; + if (nextProps.sameUser !== this.props.sameUser) { + return true; + } + + if (this.getCommentCount(nextProps) !== this.getCommentCount(this.props)) { + return true; } - var commentCount = 0; - var commentRootId; + return false; + } + getCommentCount(props) { + const post = props.post; + const parentPost = props.parentPost; + const posts = props.posts; + + let commentCount = 0; + let commentRootId; if (parentPost) { commentRootId = post.root_id; } else { commentRootId = post.id; } - for (var postId in posts) { + for (let postId in posts) { if (posts[postId].root_id === commentRootId) { commentCount += 1; } } + return commentCount; + } + render() { + var post = this.props.post; + var parentPost = this.props.parentPost; + var posts = this.props.posts; + + var type = 'Post'; + if (post.root_id && post.root_id.length > 0) { + type = 'Comment'; + } + + const commentCount = this.getCommentCount(this.props); + var rootUser; if (this.props.sameRoot) { rootUser = 'same--root'; |