From 3e7557260c3f81c996357a5756bb352137234ca3 Mon Sep 17 00:00:00 2001 From: Timur Valiev Date: Mon, 2 Dec 2019 06:23:24 -0800 Subject: [PATCH] store js app launcher settings Summary: Store JS App Launcher preferences in app settings {F223696894} Reviewed By: jknoxville Differential Revision: D18762166 fbshipit-source-id: 9da8205b6929e54c80b645789feae2715d9b1876 --- src/chrome/JSEmulatorLauncherSheet.tsx | 46 ++++++++++++++------------ src/reducers/settings.tsx | 14 ++++++++ 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/chrome/JSEmulatorLauncherSheet.tsx b/src/chrome/JSEmulatorLauncherSheet.tsx index 9cca353e6..c266fc420 100644 --- a/src/chrome/JSEmulatorLauncherSheet.tsx +++ b/src/chrome/JSEmulatorLauncherSheet.tsx @@ -21,6 +21,8 @@ import React, {Component} from 'react'; import {connect} from 'react-redux'; import {State as Store} from '../reducers'; import {launchJsEmulator} from '../utils/js-client/serverUtils'; +import {updateSettings, Action} from '../reducers/settings'; +import {Settings} from '../reducers/settings'; const Container = styled(FlexColumn)({ padding: 20, @@ -48,22 +50,33 @@ type OwnProps = { onHide: () => void; }; -type StateFromProps = {}; +type StateFromProps = { + settings: Settings; +}; -type DispatchFromProps = {}; +type DispatchFromProps = { + updateSettings: (settings: Settings) => Action; +}; type State = { url: string; - width: number; height: number; + width: number; }; type Props = OwnProps & StateFromProps & DispatchFromProps; class JSEmulatorLauncherSheet extends Component { - state: State = { - url: 'http://localhost:8888', - width: 800, - height: 600, + state: State = {...this.props.settings.jsApps.webAppLauncher}; + + applyChanges = async () => { + launchJsEmulator(this.state.url, this.state.height, this.state.width); + this.props.updateSettings({ + ...this.props.settings, + jsApps: { + webAppLauncher: {...this.state}, + }, + }); + this.props.onHide(); }; onUrlChange = (e: React.ChangeEvent) => { @@ -96,18 +109,7 @@ class JSEmulatorLauncherSheet extends Component { - @@ -117,6 +119,8 @@ class JSEmulatorLauncherSheet extends Component { } export default connect( - () => ({}), - {}, + ({settingsState}) => ({ + settings: settingsState, + }), + {updateSettings}, )(JSEmulatorLauncherSheet); diff --git a/src/reducers/settings.tsx b/src/reducers/settings.tsx index 2b1517e40..9f9833d21 100644 --- a/src/reducers/settings.tsx +++ b/src/reducers/settings.tsx @@ -24,6 +24,13 @@ export type Settings = { * of Flipper. */ enablePrefetching: Tristate; + jsApps: { + webAppLauncher: { + url: string; + height: number; + width: number; + }; + }; }; export type Action = @@ -37,6 +44,13 @@ const initialState: Settings = { androidHome: '/opt/android_sdk', enableAndroid: true, enablePrefetching: Tristate.Unset, + jsApps: { + webAppLauncher: { + url: 'http://localhost:8888', + height: 600, + width: 800, + }, + }, }; export default function reducer(