insomnia/app/containers/App.js

78 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-03-20 04:47:43 +00:00
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 {
2016-03-20 20:42:27 +00:00
componentDidMount () {
2016-03-20 04:47:43 +00:00
const {actions} = this.props;
actions.restoreState();
}
2016-03-20 20:42:27 +00:00
renderRequestPane () {
2016-03-20 04:47:43 +00:00
const {actions, requests} = this.props;
return (
2016-03-20 20:42:27 +00:00
<RequestPane
updateRequest={actions.updateRequest}
request={requests.active}/>
)
}
renderResponsePane () {
const {requests} = this.props;
return (
<ResponsePane request={requests.active}/>
2016-03-20 04:47:43 +00:00
)
}
render () {
const {actions, loading, requests} = this.props;
return (
<div className="grid bg-dark">
<Sidebar
activateRequest={actions.activateRequest}
addRequest={actions.addRequest}
loading={loading}
requests={requests}/>
2016-03-20 20:42:27 +00:00
{requests.active ? this.renderRequestPane() : <div></div>}
{requests.active ? this.renderResponsePane() : <div></div>}
2016-03-20 04:47:43 +00:00
</div>
)
}
}
App.propTypes = {
requests: PropTypes.object.isRequired,
loading: PropTypes.bool.isRequired
};
function mapStateToProps (state) {
return {
actions: state.actions,
requests: state.requests,
loading: state.loading
};
}
function mapDispatchToProps (dispatch) {
return {
actions: Object.assign(
{},
bindActionCreators(GlobalActions, dispatch),
bindActionCreators(RequestActions, dispatch)
)
}
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(App);