insomnia/app/containers/App.js

164 lines
5.6 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 {Tab, Tabs, TabList, TabPanel} from 'react-tabs';
2016-03-20 04:47:43 +00:00
2016-03-23 05:58:16 +00:00
import Editor from '../components/base/Editor'
2016-03-22 05:01:58 +00:00
import RequestBodyEditor from '../components/RequestBodyEditor'
2016-03-22 18:20:05 +00:00
import RequestUrlBar from '../components/RequestUrlBar'
2016-03-20 04:47:43 +00:00
import Sidebar from '../components/Sidebar'
import * as RequestActions from '../actions/requests'
import * as GlobalActions from '../actions/global'
// Don't inject component styles (use our own)
Tabs.setUseDefaultStyles(false);
2016-03-20 04:47:43 +00:00
class App extends Component {
2016-03-22 05:01:58 +00:00
renderPageBody (actions, activeRequest) {
2016-03-20 20:42:27 +00:00
if (!activeRequest) {
return <div></div>;
}
const updateRequestBody = actions.updateRequestBody.bind(null, activeRequest.id);
const updateRequestUrl = actions.updateRequestUrl.bind(null, activeRequest.id);
const updateRequestMethod = actions.updateRequestMethod.bind(null, activeRequest.id);
2016-03-22 05:01:58 +00:00
2016-03-20 20:42:27 +00:00
return (
<div className="grid grid-collapse">
2016-03-23 05:26:27 +00:00
<section id="request-pane" className="pane col">
<div className="grid-v">
<header className="pane__header bg-super-light">
<RequestUrlBar
onUrlChange={updateRequestUrl}
onMethodChange={updateRequestMethod}
request={activeRequest}/>
</header>
<div className="pane__body grid-v">
<Tabs selectedIndex={0} className="grid-v">
<TabList className="grid">
<Tab><button className="btn">Body</button></Tab>
<Tab><button className="btn">Params</button></Tab>
<Tab><button className="btn">Auth</button></Tab>
<Tab><button className="btn">Headers</button></Tab>
</TabList>
<TabPanel className="grid-v">
<RequestBodyEditor
className="grid-v"
onChange={updateRequestBody}
request={activeRequest}
options={{mode: activeRequest._mode}}/>
</TabPanel>
<TabPanel className="grid-v pad">Params</TabPanel>
<TabPanel className="grid-v pad">Basic Auth</TabPanel>
<TabPanel className="grid-v pad">Headers</TabPanel>
</Tabs>
</div>
</div>
</section>
2016-03-23 05:26:27 +00:00
<section id="response-pane" className="pane col">
<div className="grid-v">
<header className="pane__header text-center bg-light">
<div className="grid">
<div className="tag success"><strong>200</strong>&nbsp;SUCCESS</div>
<div className="tag">TIME&nbsp;<strong>143ms</strong></div>
</div>
</header>
<div className="pane__body grid-v">
2016-03-23 17:15:19 +00:00
<Tabs selectedIndex={0} className="grid-v">
2016-03-23 05:26:27 +00:00
<TabList className="grid">
2016-03-24 05:26:04 +00:00
<Tab><button className="btn">Response</button></Tab>
2016-03-23 05:26:27 +00:00
<Tab><button className="btn">Raw</button></Tab>
<Tab><button className="btn">Headers</button></Tab>
<Tab><button className="btn">Cookies</button></Tab>
</TabList>
<TabPanel className="grid-v">
2016-03-23 05:58:16 +00:00
<Editor
2016-03-23 05:26:27 +00:00
className="grid-v"
2016-03-23 18:34:39 +00:00
options={{
mode: 'application/json',
readOnly: true,
placeholder: 'nothing yet...'
}}/>
2016-03-23 05:26:27 +00:00
</TabPanel>
2016-03-24 05:26:04 +00:00
<TabPanel className="grid-v">
<Editor
className="grid-v"
options={{
mode: 'application/json',
readOnly: true,
placeholder: 'nothing yet...'
}}/>
</TabPanel>
2016-03-23 05:26:27 +00:00
<TabPanel className="grid-v pad">Headers</TabPanel>
<TabPanel className="grid-v pad">Cookies</TabPanel>
</Tabs>
</div>
</div>
</section>
</div>
2016-03-20 04:47:43 +00:00
)
}
2016-03-22 05:01:58 +00:00
2016-03-20 04:47:43 +00:00
render () {
2016-03-22 05:01:58 +00:00
const {actions, loading, requests} = this.props;
const activeRequest = requests.all.find(r => r.id === requests.active);
2016-03-20 04:47:43 +00:00
return (
<div className="grid bg-dark">
<Sidebar
activateRequest={actions.activateRequest}
2016-03-23 05:26:27 +00:00
changeFilter={actions.changeFilter}
2016-03-20 04:47:43 +00:00
addRequest={actions.addRequest}
2016-03-20 23:20:00 +00:00
activeRequest={activeRequest}
2016-03-23 05:26:27 +00:00
activeFilter={requests.filter}
2016-03-22 05:01:58 +00:00
loading={loading}
requests={requests.all}/>
2016-03-21 05:47:49 +00:00
<div className="col">
2016-03-22 05:01:58 +00:00
{this.renderPageBody(actions, activeRequest)}
2016-03-21 05:47:49 +00:00
</div>
2016-03-20 04:47:43 +00:00
</div>
)
}
}
App.propTypes = {
2016-03-22 05:01:58 +00:00
actions: PropTypes.shape({
activateRequest: PropTypes.func.isRequired,
updateRequestBody: PropTypes.func.isRequired,
updateRequestUrl: PropTypes.func.isRequired,
2016-03-23 05:26:27 +00:00
changeFilter: PropTypes.func.isRequired,
2016-03-22 05:01:58 +00:00
updateRequestMethod: PropTypes.func.isRequired
}).isRequired,
requests: PropTypes.shape({
all: PropTypes.array.isRequired,
active: PropTypes.string // "required" but can be null
}).isRequired,
2016-03-20 04:47:43 +00:00
loading: PropTypes.bool.isRequired
};
function mapStateToProps (state) {
return {
actions: state.actions,
2016-03-22 05:01:58 +00:00
requests: state.requests,
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);