@@ -27,6 +27,33 @@ class FeedMobile extends React.Component {
2727 }
2828 }
2929
30+ componentWillReceiveProps ( nextProps ) {
31+ // if comments just has been loaded, check if have to open the thread
32+ if ( this . props . comments . length === 0 && nextProps . comments . length > 0 ) {
33+ this . openCommentFromHash ( nextProps . comments )
34+ }
35+ }
36+
37+ componentWillMount ( ) {
38+ this . openCommentFromHash ( this . props . comments )
39+ }
40+
41+ /**
42+ * If there is hash in the URL referencing some comment,
43+ * open the comments thread by default
44+ *
45+ * @param {Array } comments list of comments
46+ */
47+ openCommentFromHash ( comments ) {
48+ const { isCommentsShown } = this . state
49+ const commentInHash = window . location . hash . match ( / # c o m m e n t - ( \d + ) / )
50+ const isCommentInTheFeed = ! ! ( commentInHash && _ . find ( comments , ( comment ) => ( comment . id . toString ( ) === commentInHash [ 1 ] ) ) )
51+
52+ if ( ! isCommentsShown && isCommentInTheFeed ) {
53+ this . toggleComments ( )
54+ }
55+ }
56+
3057 toggleComments ( ) {
3158 this . setState ( { isCommentsShown : ! this . state . isCommentsShown } )
3259 }
@@ -62,14 +89,6 @@ class FeedMobile extends React.Component {
6289 </ div >
6390 < h4 styleName = "title" > { title } </ h4 >
6491 < div styleName = "text" dangerouslySetInnerHTML = { { __html : markdownToHTML ( topicMessage . content ) } } />
65- < div styleName = "feed-actions" >
66- { totalComments > 0 ? (
67- < button className = "tc-btn tc-btn-link tc-btn-md" onClick = { this . toggleComments } > { commentsButtonText } </ button >
68- ) : (
69- < div styleName = "no-comments" > No posts yet</ div >
70- ) }
71- { allowComments && < button className = "tc-btn tc-btn-link tc-btn-md" onClick = { this . toggleNewCommentMobile } > Write a post</ button > }
72- </ div >
7392 { isCommentsShown &&
7493 < FeedComments
7594 allowComments = { allowComments }
@@ -90,6 +109,14 @@ class FeedMobile extends React.Component {
90109 allMembers = { allMembers }
91110 />
92111 }
112+ < div styleName = "feed-actions" >
113+ { totalComments > 0 ? (
114+ < button className = "tc-btn tc-btn-link tc-btn-md" onClick = { this . toggleComments } > { commentsButtonText } </ button >
115+ ) : (
116+ < div styleName = "no-comments" > No posts yet</ div >
117+ ) }
118+ { allowComments && < button className = "tc-btn tc-btn-link tc-btn-md" onClick = { this . toggleNewCommentMobile } > Write a post</ button > }
119+ </ div >
93120 { children }
94121 { isNewCommentMobileOpen &&
95122 < NewPostMobile
0 commit comments