import React, {Component, PropTypes} from 'react' import {connect} from 'react-redux' import {bindActionCreators} from 'redux' import Sidebar from '../components/Sidebar' import RequestPane from '../components/RequestPane' import ResponsePane from '../components/ResponsePane' import * as RequestActions from '../actions/requests' import * as GlobalActions from '../actions/global' class App extends Component { componentDidMount () { const {actions} = this.props; actions.restoreState(); } renderRequestPane () { const {actions, activeRequest} = this.props; return ( ) } renderResponsePane () { const {activeRequest} = this.props; return ( ) } render () { const {actions, loading, activeRequest, allRequests} = this.props; return (
{activeRequest ? this.renderRequestPane() :
} {activeRequest ? this.renderResponsePane() :
}
) } } App.propTypes = { allRequests: PropTypes.array.isRequired, activeRequest: PropTypes.object, loading: PropTypes.bool.isRequired }; function mapStateToProps (state) { return { actions: state.actions, allRequests: state.requests.all, activeRequest: state.requests.all.find(r => r.id === state.requests.active), loading: state.loading }; } function mapDispatchToProps (dispatch) { return { actions: Object.assign( {}, bindActionCreators(GlobalActions, dispatch), bindActionCreators(RequestActions, dispatch) ) } } export default connect( mapStateToProps, mapDispatchToProps )(App);