[web] Try toggle options in option modal.

This commit is contained in:
Matthew Shao 2017-07-02 12:19:32 +08:00
parent d7bbfca167
commit 2e6f56c4e7
4 changed files with 56 additions and 1 deletions

View File

@ -27,6 +27,7 @@ export default class WebsocketBackend {
this.fetchData("settings")
this.fetchData("flows")
this.fetchData("events")
this.fetchData("options")
this.store.dispatch(connectionActions.startFetching())
}

View File

@ -1,6 +1,8 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import * as modalAction from '../../ducks/ui/modal'
import { SettingsToggle } from '../Header/MenuToggle'
import { OptionsToggle } from './OptionTypes'
class PureOptionModal extends Component {
@ -26,7 +28,9 @@ class PureOptionModal extends Component {
</div>
<div className="modal-body">
...
<OptionsToggle option="http2">HTTP/2.0</OptionsToggle>
<OptionsToggle option="anticache">Anticache</OptionsToggle>
<OptionsToggle option="anticomp">Anticomp</OptionsToggle>
</div>
<div className="modal-footer">

View File

@ -0,0 +1,48 @@
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { update as updateOptions } from '../../ducks/options'
MenuToggle.propTypes = {
value: PropTypes.bool.isRequired,
onChange: PropTypes.func.isRequired,
children: PropTypes.node.isRequired,
}
export function MenuToggle({ value, onChange, children }) {
return (
<div className="menu-entry">
<label>
<input type="checkbox"
checked={value}
onChange={onChange}/>
{children}
</label>
</div>
)
}
OptionsToggle.propTypes = {
option: PropTypes.string.isRequired,
children: PropTypes.node.isRequired,
}
export function OptionsToggle({ option, children, options, updateOptions }) {
return (
<MenuToggle
value={ options[option].value }
onChange={() => {console.log(options[option]);
updateOptions({ [option]: !(options[option].value)}) }}
>
{children}
</MenuToggle>
)
}
OptionsToggle = connect(
state => ({
options: state.options,
}),
{
updateOptions,
}
)(OptionsToggle)

View File

@ -4,6 +4,7 @@ import flows from "./flows"
import settings from "./settings"
import ui from "./ui/index"
import connection from "./connection"
import options from './options'
export default combineReducers({
eventLog,
@ -11,4 +12,5 @@ export default combineReducers({
settings,
connection,
ui,
options,
})