import './site.scss'; import React from 'react'; import { connect } from 'react-redux'; import Input from './ui/Input'; import SearchForm from './form/SearchForm'; import KeymapsForm from './form/KeymapsForm'; import BlacklistForm from './form/BlacklistForm'; import PropertiesForm from './form/PropertiesForm'; import * as settingActions from '../../settings/actions/setting'; import SettingData, { JSONSettings, FormKeymaps, FormSearch, FormSettings, } from '../../shared/SettingData'; import { State as AppState } from '../reducers/setting'; import * as settings from '../../shared/Settings'; import * as PropertyDefs from '../../shared/property-defs'; const DO_YOU_WANT_TO_CONTINUE = 'Some settings in JSON can be lost when migrating. ' + 'Do you want to continue?'; type StateProps = ReturnType; interface DispatchProps { dispatch: (action: any) => void, } type Props = StateProps & DispatchProps & { // FIXME store: any; }; class SettingsComponent extends React.Component { componentDidMount() { this.props.dispatch(settingActions.load()); } renderFormFields(form: any) { let types = PropertyDefs.defs.reduce( (o: {[key: string]: string}, def) => { o[def.name] = def.type; return o; }, {}); return
Keybindings
Search Engines
Blacklist
Properties
; } renderJsonFields(json: JSONSettings, error: string) { return
; } render() { let fields = null; let disabled = this.props.error.length > 0; if (this.props.source === 'form') { fields = this.renderFormFields(this.props.form); } else if (this.props.source === 'json') { fields = this.renderJsonFields( this.props.json as JSONSettings, this.props.error); } return (

Configure Vim-Vixen

{ fields }
); } bindKeymapsForm(value: FormKeymaps) { let data = new SettingData({ source: this.props.source, form: (this.props.form as FormSettings).buildWithKeymaps(value), }); this.props.dispatch(settingActions.set(data)); } bindSearchForm(value: any) { let data = new SettingData({ source: this.props.source, form: (this.props.form as FormSettings).buildWithSearch( FormSearch.valueOf(value)), }); this.props.dispatch(settingActions.set(data)); } bindBlacklistForm(value: any) { let data = new SettingData({ source: this.props.source, form: (this.props.form as FormSettings).buildWithBlacklist( settings.blacklistValueOf(value)), }); this.props.dispatch(settingActions.set(data)); } bindPropertiesForm(value: any) { let data = new SettingData({ source: this.props.source, form: (this.props.form as FormSettings).buildWithProperties( settings.propertiesValueOf(value)), }); this.props.dispatch(settingActions.set(data)); } bindJson(_name: string, value: string) { let data = new SettingData({ source: this.props.source, json: JSONSettings.valueOf(value), }); this.props.dispatch(settingActions.set(data)); } bindSource(_name: string, value: string) { let from = this.props.source; if (from === 'form' && value === 'json') { this.props.dispatch(settingActions.switchToJson( this.props.form as FormSettings)); this.save(); } else if (from === 'json' && value === 'form') { let b = window.confirm(DO_YOU_WANT_TO_CONTINUE); if (!b) { this.forceUpdate(); return; } this.props.dispatch( settingActions.switchToForm(this.props.json as JSONSettings)); this.save(); } } save() { let { source, json, form } = this.props.store.getState(); this.props.dispatch(settingActions.save( new SettingData({ source, json, form }), )); } } const mapStateToProps = (state: AppState) => ({ ...state }); export default connect(mapStateToProps)(SettingsComponent);