From 56e74239d6b34df8f30ef046f0b0ff4ff0866a71 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Sun, 14 Jun 2015 23:53:32 -0800 Subject: first commit --- web/react/components/post_right.jsx | 397 ++++++++++++++++++++++++++++++++++++ 1 file changed, 397 insertions(+) create mode 100644 web/react/components/post_right.jsx (limited to 'web/react/components/post_right.jsx') diff --git a/web/react/components/post_right.jsx b/web/react/components/post_right.jsx new file mode 100644 index 000000000..43be60afa --- /dev/null +++ b/web/react/components/post_right.jsx @@ -0,0 +1,397 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +var PostStore = require('../stores/post_store.jsx'); +var ChannelStore = require('../stores/channel_store.jsx'); +var UserProfile = require( './user_profile.jsx' ); +var UserStore = require('../stores/user_store.jsx'); +var AppDispatcher = require('../dispatcher/app_dispatcher.jsx'); +var utils = require('../utils/utils.jsx'); +var SearchBox =require('./search_bar.jsx'); +var CreateComment = require( './create_comment.jsx' ); +var Constants = require('../utils/constants.jsx'); +var ViewImageModal = require('./view_image.jsx'); +var ActionTypes = Constants.ActionTypes; + +RhsHeaderPost = React.createClass({ + handleClose: function(e) { + e.preventDefault(); + + AppDispatcher.handleServerAction({ + type: ActionTypes.RECIEVED_SEARCH, + results: null + }); + + AppDispatcher.handleServerAction({ + type: ActionTypes.RECIEVED_POST_SELECTED, + results: null + }); + }, + handleBack: function(e) { + e.preventDefault(); + + AppDispatcher.handleServerAction({ + type: ActionTypes.RECIEVED_SEARCH_TERM, + term: this.props.fromSearch, + do_search: true, + is_mention_search: this.props.isMentionSearch + }); + + AppDispatcher.handleServerAction({ + type: ActionTypes.RECIEVED_POST_SELECTED, + results: null + }); + }, + render: function() { + var back = this.props.fromSearch ? {"< "} : ""; + + return ( +
+ {back}Message Details + +
+ ); + } +}); + +RootPost = React.createClass({ + handleImageClick: function(e) { + this.setState({startImgId: parseInt($(e.target.parentNode).attr('data-img-id'))}); + }, + getInitialState: function() { + return { startImgId: 0 }; + }, + render: function() { + + var postImageModalId = "rhs_view_image_modal_" + this.props.post.id; + var message = utils.textToJsx(this.props.post.message); + var filenames = this.props.post.filenames; + var isOwner = UserStore.getCurrentId() == this.props.post.user_id; + + var type = "Post" + if (this.props.post.root_id.length > 0) { + type = "Comment" + } + + if (filenames) { + var postFiles = []; + var images = []; + var re1 = new RegExp(' ', 'g'); + var re2 = new RegExp('\\(', 'g'); + var re3 = new RegExp('\\)', 'g'); + for (var i = 0; i < filenames.length && i < Constants.MAX_DISPLAY_FILES; i++) { + var fileSplit = filenames[i].split('.'); + if (fileSplit.length < 2) continue; + + var ext = fileSplit[fileSplit.length-1]; + fileSplit.splice(fileSplit.length-1,1) + var filePath = fileSplit.join('.'); + var filename = filePath.split('/')[filePath.split('/').length-1]; + + var ftype = utils.getFileType(ext); + + if (ftype === "image") { + var url = filePath.replace(re1, '%20').replace(re2, '%28').replace(re3, '%29'); + postFiles.push( +
+
+
+ ); + images.push(filenames[i]); + } else { + postFiles.push( +
+ +
+ +
+ ); + } + } + } + + return ( +
+
+ +
+
+
    +
  • +
  • +
  • +
    + { isOwner ? +
    + + +
    + : "" } +
    +
  • +
+
+

{message}

+ { filenames.length > 0 ? +
+ { postFiles } +
+ : "" } + { images.length > 0 ? + + : "" } +
+
+
+
+ ); + } +}); + +CommentPost = React.createClass({ + handleImageClick: function(e) { + this.setState({startImgId: parseInt($(e.target.parentNode).attr('data-img-id'))}); + }, + getInitialState: function() { + return { startImgId: 0 }; + }, + render: function() { + + var commentClass = "post"; + + var postImageModalId = "rhs_comment_view_image_modal_" + this.props.post.id; + var filenames = this.props.post.filenames; + var isOwner = UserStore.getCurrentId() == this.props.post.user_id; + + var type = "Post" + if (this.props.post.root_id.length > 0) { + type = "Comment" + } + + if (filenames) { + var postFiles = []; + var images = []; + var re1 = new RegExp(' ', 'g'); + var re2 = new RegExp('\\(', 'g'); + var re3 = new RegExp('\\)', 'g'); + for (var i = 0; i < filenames.length && i < Constants.MAX_DISPLAY_FILES; i++) { + var fileSplit = filenames[i].split('.'); + if (fileSplit.length < 2) continue; + + var ext = fileSplit[fileSplit.length-1]; + fileSplit.splice(fileSplit.length-1,1) + var filePath = fileSplit.join('.'); + var filename = filePath.split('/')[filePath.split('/').length-1]; + + var type = utils.getFileType(ext); + + if (type === "image") { + var url = filePath.replace(re1, '%20').replace(re2, '%28').replace(re3, '%29'); + postFiles.push( +
+
+
+ ); + images.push(filenames[i]); + } else { + postFiles.push( +
+ +
+ +
+ ); + } + } + } + + var message = utils.textToJsx(this.props.post.message); + + return ( +
+
+ +
+
+
    +
  • +
  • +
  • + { isOwner ? +
    + + +
    + : "" } +
  • +
+
+

{message}

+ { filenames.length > 0 ? +
+ { postFiles } +
+ : "" } + { images.length > 0 ? + + : "" } +
+
+
+ ); + } +}); + +function getStateFromStores() { + return { post_list: PostStore.getSelectedPost() }; +} + +module.exports = React.createClass({ + componentDidMount: function() { + PostStore.addSelectedPostChangeListener(this._onChange); + PostStore.addChangeListener(this._onChangeAll); + $(".post-right__scroll").perfectScrollbar(); + this.resize(); + var self = this; + $(window).resize(function(){ + self.resize(); + }); + }, + componentDidUpdate: function() { + this.resize(); + }, + componentWillUnmount: function() { + PostStore.removeSelectedPostChangeListener(this._onChange); + PostStore.removeChangeListener(this._onChangeAll); + }, + _onChange: function() { + if (this.isMounted()) { + var newState = getStateFromStores(); + if (!utils.areStatesEqual(newState, this.state)) { + this.setState(newState); + } + } + }, + _onChangeAll: function() { + + if (this.isMounted()) { + + // if something was changed in the channel like adding a + // comment or post then lets refresh the sidebar list + var currentSelected = PostStore.getSelectedPost(); + if (!currentSelected || currentSelected.order.length == 0) { + return; + } + + var currentPosts = PostStore.getPosts(currentSelected.posts[currentSelected.order[0]].channel_id); + + if (!currentPosts || currentPosts.order.length == 0) { + return; + } + + + if (currentPosts.posts[currentPosts.order[0]].channel_id == currentSelected.posts[currentSelected.order[0]].channel_id) { + currentSelected.posts = {}; + for (var postId in currentPosts.posts) { + currentSelected.posts[postId] = currentPosts.posts[postId]; + } + + PostStore.storeSelectedPost(currentSelected); + } + + this.setState(getStateFromStores()); + } + }, + getInitialState: function() { + return getStateFromStores(); + }, + resize: function() { + var height = $(window).height() - $('#error_bar').outerHeight() - 100; + $(".post-right__scroll").css("height", height + "px"); + $(".post-right__scroll").scrollTop(100000); + $(".post-right__scroll").perfectScrollbar('update'); + }, + render: function() { + + var post_list = this.state.post_list; + + if (post_list == null) { + return ( +
+ ); + } + + var selected_post = post_list.posts[post_list.order[0]]; + var root_post = null; + + if (selected_post.root_id == "") { + root_post = selected_post; + } + else { + root_post = post_list.posts[selected_post.root_id]; + } + + var posts_array = []; + + for (var postId in post_list.posts) { + var cpost = post_list.posts[postId]; + if (cpost.root_id == root_post.id) { + posts_array.push(cpost); + } + } + + posts_array.sort(function(a,b) { + if (a.create_at < b.create_at) + return -1; + if (a.create_at > b.create_at) + return 1; + return 0; + }); + + var results = this.state.results; + var currentId = UserStore.getCurrentId(); + var searchForm = currentId == null ? null : ; + + return ( +
+
{searchForm}
+
+ +
+ +
+ { posts_array.map(function(cpost) { + return + })} +
+
+ +
+
+
+
+ ); + } +}); -- cgit v1.2.3-1-g7c22