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_body.jsx | 141 +++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 web/react/components/post_body.jsx (limited to 'web/react/components/post_body.jsx') diff --git a/web/react/components/post_body.jsx b/web/react/components/post_body.jsx new file mode 100644 index 000000000..55fc32c33 --- /dev/null +++ b/web/react/components/post_body.jsx @@ -0,0 +1,141 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +var CreateComment = require( './create_comment.jsx' ); +var UserStore = require('../stores/user_store.jsx'); +var utils = require('../utils/utils.jsx'); +var ViewImageModal = require('./view_image.jsx'); +var Constants = require('../utils/constants.jsx'); + +module.exports = React.createClass({ + handleImageClick: function(e) { + this.setState({startImgId: parseInt($(e.target.parentNode).attr('data-img-id'))}); + }, + componentWillReceiveProps: function(nextProps) { + var linkData = utils.extractLinks(nextProps.post.message); + this.setState({ links: linkData["links"], message: linkData["text"] }); + }, + componentDidMount: function() { + var filenames = this.props.post.filenames; + var self = this; + if (filenames) { + 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 fileInfo = utils.splitFileLocation(filenames[i]); + if (Object.keys(fileInfo).length === 0) continue; + + var type = utils.getFileType(fileInfo.ext); + + if (type === "image") { + $('').attr('src', fileInfo.path+'_thumb.jpg').load(function(path, name){ return function() { + $(this).remove(); + if (name in self.refs) { + var imgDiv = self.refs[name].getDOMNode(); + $(imgDiv).removeClass('post__load'); + $(imgDiv).addClass('post__image'); + var url = path.replace(re1, '%20').replace(re2, '%28').replace(re3, '%29'); + $(imgDiv).css('background-image', 'url('+url+'_thumb.jpg)'); + } + }}(fileInfo.path, filenames[i])); + } + } + } + }, + getInitialState: function() { + var linkData = utils.extractLinks(this.props.post.message); + return { startImgId: 0, links: linkData["links"], message: linkData["text"] }; + }, + render: function() { + var post = this.props.post; + var filenames = this.props.post.filenames; + var parentPost = this.props.parentPost; + var postImageModalId = "view_image_modal_" + post.id; + var inner = utils.textToJsx(this.state.message); + + var comment = ""; + var reply = ""; + var postClass = ""; + + if (parentPost) { + var profile = UserStore.getProfile(parentPost.user_id); + var apostrophe = ""; + var name = "..."; + if (profile != null) { + if (profile.username.slice(-1) === 's') { + apostrophe = "'"; + } else { + apostrophe = "'s"; + } + name = {profile.username}; + } + + var message = parentPost.message; + + comment = ( +

+ Commented on {name}{apostrophe} message: {utils.replaceHtmlEntities(message)} +

+ ); + + postClass += " post-comment"; + } + + var postFiles = []; + var images = []; + if (filenames) { + for (var i = 0; i < filenames.length && i < Constants.MAX_DISPLAY_FILES; i++) { + var fileInfo = utils.splitFileLocation(filenames[i]); + if (Object.keys(fileInfo).length === 0) continue; + + var type = utils.getFileType(fileInfo.ext); + + if (type === "image") { + postFiles.push( +
+
+
+ ); + images.push(filenames[i]); + } else { + postFiles.push( +
+ +
+ +
+ ); + } + } + } + + var embed; + if (postFiles.length === 0 && this.state.links) { + embed = utils.getEmbed(this.state.links[0]); + } + + return ( +
+ { comment } +

{inner}

+ { filenames && filenames.length > 0 ? +
+ { postFiles } +
+ : "" } + { embed } + + { images.length > 0 ? + + : "" } +
+ ); + } +}); -- cgit v1.2.3-1-g7c22