diff options
author | hmhealey <harrisonmhealey@gmail.com> | 2015-07-23 16:45:16 -0400 |
---|---|---|
committer | hmhealey <harrisonmhealey@gmail.com> | 2015-07-29 09:52:08 -0400 |
commit | 5488b5e2164518d9b2a745a9906152a4e6c0be10 (patch) | |
tree | bb4d4059e952f8321a8511ff6a5dd9f21b6ac416 /web/react/components/file_attachment_list.jsx | |
parent | eddb79d97d72a63fc3af6741567077e3e59b2871 (diff) | |
download | chat-5488b5e2164518d9b2a745a9906152a4e6c0be10.tar.gz chat-5488b5e2164518d9b2a745a9906152a4e6c0be10.tar.bz2 chat-5488b5e2164518d9b2a745a9906152a4e6c0be10.zip |
Reconcile the code to display attachment previews into a FileAttachmentList class to clean up duplicated code.
Diffstat (limited to 'web/react/components/file_attachment_list.jsx')
-rw-r--r-- | web/react/components/file_attachment_list.jsx | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/web/react/components/file_attachment_list.jsx b/web/react/components/file_attachment_list.jsx new file mode 100644 index 000000000..0b52d6a70 --- /dev/null +++ b/web/react/components/file_attachment_list.jsx @@ -0,0 +1,47 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +var ViewImageModal = require('./view_image.jsx'); +var FileAttachment = require('./file_attachment.jsx'); +var Constants = require('../utils/constants.jsx'); + +module.exports = React.createClass({ + displayName: "FileAttachmentList", + propTypes: { + filenames: React.PropTypes.arrayOf(React.PropTypes.string).isRequired, + postId: React.PropTypes.string.isRequired, + channelId: React.PropTypes.string, + userId: React.PropTypes.string + }, + getInitialState: function() { + return {startImgId: 0}; + }, + render: function() { + var filenames = this.props.filenames; + + var postImageModalId = "view_image_modal_" + this.props.postId; + + var postFiles = []; + for (var i = 0; i < filenames.length && i < Constants.MAX_DISPLAY_FILES; i++) { + postFiles.push(<FileAttachment key={i} filenames={filenames} index={i} imageModalId={postImageModalId} handleImageClick={this.handleImageClick} />); + } + + return ( + <div> + <div className="post-image__columns"> + {postFiles} + </div> + <ViewImageModal + channelId={this.props.channelId} + userId={this.props.userId} + modalId={postImageModalId} + startId={this.state.startImgId} + imgCount={0} + filenames={filenames} /> + </div> + ); + }, + handleImageClick: function(e) { + this.setState({startImgId: parseInt($(e.target.parentNode).attr('data-img-id'))}); + } +}); |