Reconcile the code to display attachment previews into a FileAttachmentList class to clean up duplicated code.

Этот коммит содержится в:
hmhealey
2015-07-23 16:45:16 -04:00
родитель eddb79d97d
Коммит 5488b5e216
4 изменённых файлов: 176 добавлений и 234 удалений

Просмотреть файл

@@ -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'))});
}
});