import React, { Component, PropTypes } from 'react' import { connect } from 'react-redux' import { MessageUtils } from '../flow/utils.js' import * as ContentViews from './ContentView/ContentViews' import * as MetaViews from './ContentView/MetaViews' import ContentLoader from './ContentView/ContentLoader' import ViewSelector from './ContentView/ViewSelector' import { setContentView, displayLarge, updateEdit } from '../ducks/ui/flow' ContentView.propTypes = { // It may seem a bit weird at the first glance: // Every view takes the flow and the message as props, e.g. // flow: React.PropTypes.object.isRequired, message: React.PropTypes.object.isRequired, } ContentView.isContentTooLarge = msg => msg.contentLength > 1024 * 1024 * (ContentViews.ViewImage.matches(msg) ? 10 : 0.2) function ContentView(props) { const { flow, message, contentView, selectView, displayLarge, setDisplayLarge, lastFileUpload, uploadContent, onContentChange, content, readonly } = props if (message.contentLength === 0) { return } if (message.contentLength === null) { return } if (!displayLarge && ContentView.isContentTooLarge(message)) { return } const View = ContentViews[contentView] return (
{View.textView ? ( ) : ( )}
    ContentView.fileInput.click()} title="Upload a file to replace the content." > ContentView.fileInput = ref} className="hidden" type="file" onChange={e => {if(e.target.files.length > 0) uploadContent(e.target.files[0])}} />
) } export default connect( state => ({ contentView: state.ui.flow.contentView, displayLarge: state.ui.flow.displayLarge, lastFileUpload: state.ui.flow.lastFileUpload }), { selectView: setContentView, displayLarge, updateEdit, } )(ContentView)