var React = require('react'); var ReactDOM = require('react-dom'); var PropTypes = require('prop-types'); var reactUtil = require('../util/reactUtil'); var keyMirror = require('../util/keyMirror'); var STATUSES = keyMirror({ inqueue: null, processing: null, finished: null }); class CommandView extends React.Component{ componentDidMount() { this.props.command.on('change', this.updateStateFromModel, this); this.updateStateFromModel(); } componentWillUnmount() { this.props.command.off('change', this.updateStateFromModel, this); } updateStateFromModel() { var commandJSON = this.props.command.toJSON(); this.setState({ status: commandJSON.status, rawStr: commandJSON.rawStr, warnings: commandJSON.warnings, result: commandJSON.result }); } constructor(props, context) { super(props, context); this.state = { status: STATUSES.inqueue, rawStr: 'git commit', warnings: [], result: '' }; } render() { var commandClass = reactUtil.joinClasses([ this.state.status, 'commandLine', 'transitionBackground' ]); return (

{'$'} {' '}

{this.renderResult()}
{this.renderFormattedWarnings()}
); } renderResult() { if (!this.state.result) { return null; } // We are going to get a ton of raw markup here // so lets split into paragraphs ourselves var paragraphs = this.state.result.split("\n"); var result = []; for (var i = 0; i < paragraphs.length; i++) { if (paragraphs[i].startsWith('https://')) { result.push( ); } else { result.push(

); } } return (

{result}
); } renderFormattedWarnings() { var warnings = this.state.warnings; var result = []; for (var i = 0; i < warnings.length; i++) { result.push(

{warnings[i]}

); } return result; } }; CommandView.propTypes = { // the backbone command model command: PropTypes.object.isRequired, id: PropTypes.string, }; module.exports = CommandView;