aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/components/ProxyApp.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/js/components/ProxyApp.jsx')
-rw-r--r--web/src/js/components/ProxyApp.jsx121
1 files changed, 20 insertions, 101 deletions
diff --git a/web/src/js/components/ProxyApp.jsx b/web/src/js/components/ProxyApp.jsx
index 1ac979bc..2962fc2b 100644
--- a/web/src/js/components/ProxyApp.jsx
+++ b/web/src/js/components/ProxyApp.jsx
@@ -4,6 +4,7 @@ import _ from 'lodash'
import { connect } from 'react-redux'
import { init as appInit, destruct as appDestruct } from '../ducks/app'
+import { onKeyDown } from '../ducks/ui'
import Header from './Header'
import EventLog from './EventLog'
import Footer from './Footer'
@@ -11,124 +12,39 @@ import { Key } from '../utils.js'
class ProxyAppMain extends Component {
- static childContextTypes = {
- returnFocus: PropTypes.func.isRequired,
- }
-
static contextTypes = {
router: PropTypes.object.isRequired,
}
- constructor(props, context) {
- super(props, context)
-
- this.focus = this.focus.bind(this)
- this.onKeyDown = this.onKeyDown.bind(this)
- this.updateLocation = this.updateLocation.bind(this)
- }
-
componentWillMount() {
- this.props.appInit()
- }
-
- /**
- * @todo listen to window's key events
- */
- componentDidMount() {
- this.focus()
+ this.props.appInit(this.context.router)
+ window.addEventListener('keydown', this.props.onKeyDown);
}
componentWillUnmount() {
- this.props.appDestruct()
- }
-
- /**
- * @todo use props
- */
- getChildContext() {
- return { returnFocus: this.focus }
- }
-
- /**
- * @todo remove it
- */
- focus() {
- document.activeElement.blur()
- window.getSelection().removeAllRanges()
- ReactDOM.findDOMNode(this).focus()
- }
-
- /**
- * @todo move to actions
- * @todo bind on window
- */
- onKeyDown(e) {
- let name = null
-
- switch (e.keyCode) {
- case Key.I:
- name = 'intercept'
- break
- case Key.L:
- name = 'search'
- break
- case Key.H:
- name = 'highlight'
- break
- default:
- let main = this.refs.view
- if (this.refs.view.refs.wrappedInstance) {
- main = this.refs.view.refs.wrappedInstance
- }
- if (main.onMainKeyDown) {
- main.onMainKeyDown(e)
- }
- return // don't prevent default then
- }
-
- if (name) {
- const headerComponent = this.refs.header.refs.wrappedInstance || this.refs.header
- headerComponent.setState({ active: Header.entries[0] }, () => {
- const active = headerComponent.refs.active.refs.wrappedInstance || headerComponent.refs.active
- active.refs[name].select()
- })
- }
-
- e.preventDefault()
+ this.props.appDestruct(this.context.router)
+ window.removeEventListener('keydown', this.props.onKeyDown);
}
- /**
- * @todo move to actions
- */
- updateLocation(pathname, queryUpdate) {
- if (pathname === undefined) {
- pathname = this.props.location.pathname
+ componentWillReceiveProps(nextProps) {
+ if (nextProps.query === this.props.query && nextProps.selectedFlowId === this.props.selectedFlowId && nextProps.panel === this.props.panel) {
+ return
}
- const query = this.props.location.query
- for (const key of Object.keys(queryUpdate || {})) {
- query[key] = queryUpdate[key] || undefined
+ if (nextProps.selectedFlowId) {
+ this.context.router.replace({ pathname: `/flows/${nextProps.selectedFlowId}/${nextProps.panel}`, query: nextProps.query })
+ } else {
+ this.context.router.replace({ pathname: '/flows', query: nextProps.query })
}
- this.context.router.replace({ pathname, query })
- }
-
- /**
- * @todo pass in with props
- */
- getQuery() {
- // For whatever reason, react-router always returns the same object, which makes comparing
- // the current props with nextProps impossible. As a workaround, we just clone the query object.
- return _.clone(this.props.location.query)
}
render() {
- const { showEventLog, location, children } = this.props
- const query = this.getQuery()
+ const { showEventLog, location, children, query } = this.props
return (
- <div id="container" tabIndex="0" onKeyDown={this.onKeyDown}>
- <Header ref="header" updateLocation={this.updateLocation} query={query} />
+ <div id="container" tabIndex="0">
+ <Header ref="header" query={query} />
{React.cloneElement(
children,
- { ref: 'view', location, query, updateLocation: this.updateLocation }
+ { ref: 'view', location, query }
)}
{showEventLog && (
<EventLog key="eventlog"/>
@@ -142,10 +58,13 @@ class ProxyAppMain extends Component {
export default connect(
state => ({
showEventLog: state.eventLog.visible,
- settings: state.settings.settings,
+ query: state.ui.query,
+ panel: state.ui.panel,
+ selectedFlowId: state.flows.selected[0]
}),
{
appInit,
appDestruct,
+ onKeyDown
}
)(ProxyAppMain)