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
|
|
|
renderRequestPane () {
|
2016-03-20 23:20:00 +00:00
|
|
|
const {actions, activeRequest} = this.props;
|
2016-03-20 04:47:43 +00:00
|
|
|
return (
|
2016-03-20 20:42:27 +00:00
|
|
|
<RequestPane
|
2016-03-20 23:20:00 +00:00
|
|
|
updateRequestBody={actions.updateRequestBody.bind(null, activeRequest.id)}
|
|
|
|
updateRequestUrl={actions.updateRequestUrl.bind(null, activeRequest.id)}
|
2016-03-20 23:27:46 +00:00
|
|
|
updateRequestMethod={actions.updateRequestMethod.bind(null, activeRequest.id)}
|
2016-03-20 23:20:00 +00:00
|
|
|
request={activeRequest}
|
|
|
|
/>
|
2016-03-20 20:42:27 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderResponsePane () {
|
2016-03-20 23:20:00 +00:00
|
|
|
const {activeRequest} = this.props;
|
2016-03-20 20:42:27 +00:00
|
|
|
return (
|
2016-03-20 23:20:00 +00:00
|
|
|
<ResponsePane request={activeRequest}/>
|
2016-03-20 04:47:43 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2016-03-20 23:20:00 +00:00
|
|
|
const {actions, loading, activeRequest, allRequests} = this.props;
|
2016-03-20 04:47:43 +00:00
|
|
|
return (
|
|
|
|
<div className="grid bg-dark">
|
|
|
|
<Sidebar
|
|
|
|
activateRequest={actions.activateRequest}
|
|
|
|
addRequest={actions.addRequest}
|
|
|
|
loading={loading}
|
2016-03-20 23:20:00 +00:00
|
|
|
activeRequest={activeRequest}
|
2016-03-21 05:47:49 +00:00
|
|
|
requests={allRequests}/>
|
|
|
|
<div className="col">
|
|
|
|
<div className="grid grid-collapse">
|
|
|
|
{activeRequest ? this.renderRequestPane() : <div></div>}
|
|
|
|
{activeRequest ? this.renderResponsePane() : <div></div>}
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-03-20 04:47:43 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
App.propTypes = {
|
2016-03-20 23:20:00 +00:00
|
|
|
allRequests: PropTypes.array.isRequired,
|
|
|
|
activeRequest: PropTypes.object,
|
2016-03-20 04:47:43 +00:00
|
|
|
loading: PropTypes.bool.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
return {
|
|
|
|
actions: state.actions,
|
2016-03-20 23:20:00 +00:00
|
|
|
allRequests: state.requests.all,
|
2016-03-20 23:27:46 +00:00
|
|
|
activeRequest: state.requests.all.find(r => r.id === state.requests.active),
|
2016-03-20 04:47:43 +00:00
|
|
|
loading: state.loading
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return {
|
|
|
|
actions: Object.assign(
|
|
|
|
{},
|
|
|
|
bindActionCreators(GlobalActions, dispatch),
|
|
|
|
bindActionCreators(RequestActions, dispatch)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(App);
|
|
|
|
|