From 12896bd23eeba79884245c1c29fdc568cf21a7fa Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 14 Mar 2016 08:50:46 -0400 Subject: Converting to Webpack. Stage 1. --- webapp/components/rhs_comment.jsx | 311 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 311 insertions(+) create mode 100644 webapp/components/rhs_comment.jsx (limited to 'webapp/components/rhs_comment.jsx') diff --git a/webapp/components/rhs_comment.jsx b/webapp/components/rhs_comment.jsx new file mode 100644 index 000000000..29986d415 --- /dev/null +++ b/webapp/components/rhs_comment.jsx @@ -0,0 +1,311 @@ +// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import ReactDOM from 'react-dom'; +import PostStore from 'stores/post_store.jsx'; +import ChannelStore from 'stores/channel_store.jsx'; +import UserProfile from './user_profile.jsx'; +import UserStore from 'stores/user_store.jsx'; +import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; +import * as Utils from 'utils/utils.jsx'; +import Constants from 'utils/constants.jsx'; +import FileAttachmentList from './file_attachment_list.jsx'; +import * as Client from 'utils/client.jsx'; +import * as AsyncClient from 'utils/async_client.jsx'; +var ActionTypes = Constants.ActionTypes; +import * as TextFormatting from 'utils/text_formatting.jsx'; +import twemoji from 'twemoji'; +import * as GlobalActions from 'action_creators/global_actions.jsx'; + +import {intlShape, injectIntl, defineMessages, FormattedMessage, FormattedDate} from 'react-intl'; + +import loadingGif from 'images/load.gif'; + +const holders = defineMessages({ + comment: { + id: 'rhs_comment.comment', + defaultMessage: 'Comment' + } +}); + +import React from 'react'; + +class RhsComment extends React.Component { + constructor(props) { + super(props); + + this.retryComment = this.retryComment.bind(this); + this.parseEmojis = this.parseEmojis.bind(this); + this.handlePermalink = this.handlePermalink.bind(this); + + this.state = {}; + } + retryComment(e) { + e.preventDefault(); + + var post = this.props.post; + Client.createPost(post, post.channel_id, + (data) => { + AsyncClient.getPosts(post.channel_id); + + var channel = ChannelStore.get(post.channel_id); + var member = ChannelStore.getMember(post.channel_id); + member.msg_count = channel.total_msg_count; + member.last_viewed_at = (new Date()).getTime(); + ChannelStore.setChannelMember(member); + + AppDispatcher.handleServerAction({ + type: ActionTypes.RECEIVED_POST, + post: data + }); + }, + () => { + post.state = Constants.POST_FAILED; + PostStore.updatePendingPost(post); + this.forceUpdate(); + } + ); + + post.state = Constants.POST_LOADING; + PostStore.updatePendingPost(post); + this.forceUpdate(); + } + parseEmojis() { + twemoji.parse(ReactDOM.findDOMNode(this), {size: Constants.EMOJI_SIZE}); + } + handlePermalink(e) { + e.preventDefault(); + GlobalActions.showGetPostLinkModal(this.props.post); + } + componentDidMount() { + this.parseEmojis(); + } + shouldComponentUpdate(nextProps) { + if (!Utils.areObjectsEqual(nextProps.post, this.props.post)) { + return true; + } + + return false; + } + componentDidUpdate() { + this.parseEmojis(); + } + createDropdown() { + var post = this.props.post; + + if (post.state === Constants.POST_FAILED || post.state === Constants.POST_LOADING || post.state === Constants.POST_DELETED) { + return ''; + } + + var isOwner = UserStore.getCurrentId() === post.user_id; + var isAdmin = Utils.isAdmin(UserStore.getCurrentUser().roles); + + var dropdownContents = []; + + if (!Utils.isMobile()) { + dropdownContents.push( +
  • + + + +
  • + ); + } + + if (isOwner) { + dropdownContents.push( +
  • + + + +
  • + ); + } + + if (isOwner || isAdmin) { + dropdownContents.push( +
  • + GlobalActions.showDeletePostModal(post, 0)} + > + + +
  • + ); + } + + if (dropdownContents.length === 0) { + return ''; + } + + return ( +
    +
    + + + ); + } else if (post.state === Constants.POST_LOADING) { + postClass += ' post-waiting'; + loading = ( + + ); + } else if (this.props.post.state === Constants.POST_DELETED) { + message = ( + + ); + } + + var dropdown = this.createDropdown(); + + var fileAttachment; + if (post.filenames && post.filenames.length > 0) { + fileAttachment = ( + + ); + } + + return ( +
    +
    +
    + +
    +
    +
      +
    • + +
    • +
    • + +
    • +
    • + {dropdown} +
    • +
    +
    +
    + {loading} + {message} +
    + {fileAttachment} +
    +
    +
    +
    + ); + } +} + +RhsComment.defaultProps = { + post: null +}; +RhsComment.propTypes = { + intl: intlShape.isRequired, + post: React.PropTypes.object, + user: React.PropTypes.object +}; + +export default injectIntl(RhsComment); -- cgit v1.2.3-1-g7c22