/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format */ import {FlexColumn, Button, styled, Text, FlexRow, Spacer} from 'flipper'; import React, {Component} from 'react'; import {updateSettings, Action} from '../reducers/settings'; import { Action as LauncherAction, LauncherSettings, updateLauncherSettings, } from '../reducers/launcherSettings'; import {connect} from 'react-redux'; import {State as Store} from '../reducers'; import {Settings, DEFAULT_ANDROID_SDK_PATH} from '../reducers/settings'; import {flush} from '../utils/persistor'; import ToggledSection from './settings/ToggledSection'; import {FilePathConfigField, ConfigText} from './settings/configFields'; import KeyboardShortcutInput from './settings/KeyboardShortcutInput'; import {isEqual} from 'lodash'; import restartFlipper from '../utils/restartFlipper'; import LauncherSettingsPanel from '../fb-stubs/LauncherSettingsPanel'; import {reportUsage} from '../utils/metrics'; const Container = styled(FlexColumn)({ padding: 20, width: 800, }); const Title = styled(Text)({ marginBottom: 18, marginRight: 10, fontWeight: 100, fontSize: '40px', }); type OwnProps = { onHide: () => void; platform: NodeJS.Platform; }; type StateFromProps = { settings: Settings; launcherSettings: LauncherSettings; isXcodeDetected: boolean; }; type DispatchFromProps = { updateSettings: (settings: Settings) => Action; updateLauncherSettings: (settings: LauncherSettings) => LauncherAction; }; type State = { updatedSettings: Settings; updatedLauncherSettings: LauncherSettings; }; type Props = OwnProps & StateFromProps & DispatchFromProps; class SettingsSheet extends Component { state: State = { updatedSettings: {...this.props.settings}, updatedLauncherSettings: {...this.props.launcherSettings}, }; componentDidMount() { reportUsage('settings:opened'); } applyChanges = async () => { this.props.updateSettings(this.state.updatedSettings); this.props.updateLauncherSettings(this.state.updatedLauncherSettings); this.props.onHide(); flush().then(() => { restartFlipper(); }); }; render() { const { enableAndroid, androidHome, enableIOS, enablePhysicalIOS, enablePrefetching, idbPath, reactNative, } = this.state.updatedSettings; return ( Settings { this.setState({ updatedSettings: { ...this.state.updatedSettings, enableAndroid: v, }, }); }}> { this.setState({ updatedSettings: { ...this.state.updatedSettings, androidHome: v, }, }); }} /> { this.setState({ updatedSettings: {...this.state.updatedSettings, enableIOS: v}, }); }}> {' '} {this.props.platform === 'darwin' && ( )} {this.props.platform !== 'darwin' && ( )} { this.setState({ updatedSettings: { ...this.state.updatedSettings, enablePhysicalIOS: v, }, }); }}> { this.setState({ updatedSettings: {...this.state.updatedSettings, idbPath: v}, }); }} /> { this.setState({ updatedSettings: { ...this.state.updatedSettings, enablePrefetching: v, }, }); }} isLocalPinIgnored={this.state.updatedLauncherSettings.ignoreLocalPin} onIgnoreLocalPinChange={(v) => { this.setState({ updatedLauncherSettings: { ...this.state.updatedLauncherSettings, ignoreLocalPin: v, }, }); }} /> { this.setState((prevState) => ({ updatedSettings: { ...prevState.updatedSettings, reactNative: { ...prevState.updatedSettings.reactNative, shortcuts: { ...prevState.updatedSettings.reactNative.shortcuts, enabled, }, }, }, })); }}> { this.setState((prevState) => ({ updatedSettings: { ...prevState.updatedSettings, reactNative: { ...prevState.updatedSettings.reactNative, shortcuts: { ...prevState.updatedSettings.reactNative.shortcuts, reload, }, }, }, })); }} /> { this.setState((prevState) => ({ updatedSettings: { ...prevState.updatedSettings, reactNative: { ...prevState.updatedSettings.reactNative, shortcuts: { ...prevState.updatedSettings.reactNative.shortcuts, openDevMenu, }, }, }, })); }} />
); } } export default connect( ({settingsState, launcherSettingsState, application}) => ({ settings: settingsState, launcherSettings: launcherSettingsState, isXcodeDetected: application.xcodeCommandLineToolsDetected, }), {updateSettings, updateLauncherSettings}, )(SettingsSheet);