From 76d54190a0abb4c03ca7207ae50eff02190ba89a Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Fri, 14 Aug 2015 11:36:51 -0400 Subject: reformatting and minor refactoring of post_*.jsx to match style guide --- web/react/components/post.jsx | 4 +- web/react/components/post_body.jsx | 12 +++--- web/react/components/post_info.jsx | 84 ++++++++++++++++++++++++-------------- 3 files changed, 62 insertions(+), 38 deletions(-) (limited to 'web') diff --git a/web/react/components/post.jsx b/web/react/components/post.jsx index 4b66e175c..b798dc7ca 100644 --- a/web/react/components/post.jsx +++ b/web/react/components/post.jsx @@ -74,9 +74,9 @@ module.exports = React.createClass({ var parentPost = this.props.parentPost; var posts = this.props.posts; - var type = "Post"; + var type = 'Post'; if (post.root_id && post.root_id.length > 0) { - type = "Comment"; + type = 'Comment'; } var commentCount = 0; diff --git a/web/react/components/post_body.jsx b/web/react/components/post_body.jsx index 7abf38838..13722857e 100644 --- a/web/react/components/post_body.jsx +++ b/web/react/components/post_body.jsx @@ -31,9 +31,9 @@ module.exports = React.createClass({ var name = "..."; if (profile != null) { if (profile.username.slice(-1) === 's') { - apostrophe = "'"; + apostrophe = '\''; } else { - apostrophe = "'s"; + apostrophe = '\'s'; } name = {profile.username}; } @@ -62,11 +62,11 @@ module.exports = React.createClass({ var loading; if (post.state === Constants.POST_FAILED) { - postClass += " post-fail"; - loading = Retry; + postClass += ' post-fail'; + loading = Retry; } else if (post.state === Constants.POST_LOADING) { - postClass += " post-waiting"; - loading = ; + postClass += ' post-waiting'; + loading = ; } var embed; diff --git a/web/react/components/post_info.jsx b/web/react/components/post_info.jsx index 37e525717..f6ab0ed8a 100644 --- a/web/react/components/post_info.jsx +++ b/web/react/components/post_info.jsx @@ -12,44 +12,68 @@ module.exports = React.createClass({ }, render: function() { var post = this.props.post; - var isOwner = UserStore.getCurrentId() == post.user_id; - var isAdmin = UserStore.getCurrentUser().roles.indexOf("admin") > -1 + var isOwner = UserStore.getCurrentId() === post.user_id; + var isAdmin = UserStore.getCurrentUser().roles.indexOf('admin') > -1; - var type = "Post"; + var type = 'Post'; if (post.root_id && post.root_id.length > 0) { - type = "Comment"; + type = 'Comment'; } - var comments = ""; - var lastCommentClass = this.props.isLastComment ? " comment-icon__container__show" : " comment-icon__container__hide"; - if (this.props.commentCount >= 1 && post.state !== Constants.POST_FAILED && post.state !== Constants.POST_LOADING) { - comments = {this.props.commentCount}; + var comments = ''; + var lastCommentClass = ' comment-icon__container__hide'; + if (this.props.isLastComment) { + lastCommentClass = ' comment-icon__container__show'; } - var show_dropdown = isOwner || (this.props.allowReply === "true" && type != "Comment"); - if (post.state === Constants.POST_FAILED || post.state === Constants.POST_LOADING) show_dropdown = false; + if (this.props.commentCount >= 1 && post.state !== Constants.POST_FAILED && post.state !== Constants.POST_LOADING) { + comments = {this.props.commentCount}; + } + + var showDropdown = isOwner || (this.props.allowReply === 'true' && type !== 'Comment'); + if (post.state === Constants.POST_FAILED || post.state === Constants.POST_LOADING) { + showDropdown = false; + } + + var dropdownContents = []; + var dropdown; + if (showDropdown) { + var dataComments = 0; + if (type === 'Post') { + dataComments = this.props.commentCount; + } + + if (isOwner) { + dropdownContents.push(
  • Edit
  • ); + } + + if (isOwner || isAdmin) { + dropdownContents.push(
  • Delete
  • ); + } + + if (this.props.allowReply === 'true') { + dropdownContents.push(
  • Reply
  • ); + } + + dropdown = ( +
    +