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
This commit is contained in:
committed by
Facebook Github Bot
parent
fe4af064cf
commit
3e7557260c
@@ -21,6 +21,8 @@ import React, {Component} from 'react';
|
|||||||
import {connect} from 'react-redux';
|
import {connect} from 'react-redux';
|
||||||
import {State as Store} from '../reducers';
|
import {State as Store} from '../reducers';
|
||||||
import {launchJsEmulator} from '../utils/js-client/serverUtils';
|
import {launchJsEmulator} from '../utils/js-client/serverUtils';
|
||||||
|
import {updateSettings, Action} from '../reducers/settings';
|
||||||
|
import {Settings} from '../reducers/settings';
|
||||||
|
|
||||||
const Container = styled(FlexColumn)({
|
const Container = styled(FlexColumn)({
|
||||||
padding: 20,
|
padding: 20,
|
||||||
@@ -48,22 +50,33 @@ type OwnProps = {
|
|||||||
onHide: () => void;
|
onHide: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
type StateFromProps = {};
|
type StateFromProps = {
|
||||||
|
settings: Settings;
|
||||||
|
};
|
||||||
|
|
||||||
type DispatchFromProps = {};
|
type DispatchFromProps = {
|
||||||
|
updateSettings: (settings: Settings) => Action;
|
||||||
|
};
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
url: string;
|
url: string;
|
||||||
width: number;
|
|
||||||
height: number;
|
height: number;
|
||||||
|
width: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Props = OwnProps & StateFromProps & DispatchFromProps;
|
type Props = OwnProps & StateFromProps & DispatchFromProps;
|
||||||
class JSEmulatorLauncherSheet extends Component<Props, State> {
|
class JSEmulatorLauncherSheet extends Component<Props, State> {
|
||||||
state: State = {
|
state: State = {...this.props.settings.jsApps.webAppLauncher};
|
||||||
url: 'http://localhost:8888',
|
|
||||||
width: 800,
|
applyChanges = async () => {
|
||||||
height: 600,
|
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<HTMLInputElement>) => {
|
onUrlChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
@@ -96,18 +109,7 @@ class JSEmulatorLauncherSheet extends Component<Props, State> {
|
|||||||
<Button compact padded onClick={this.props.onHide}>
|
<Button compact padded onClick={this.props.onHide}>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button type="primary" compact padded onClick={this.applyChanges}>
|
||||||
type="primary"
|
|
||||||
compact
|
|
||||||
padded
|
|
||||||
onClick={() => {
|
|
||||||
launchJsEmulator(
|
|
||||||
this.state.url,
|
|
||||||
this.state.height,
|
|
||||||
this.state.width,
|
|
||||||
);
|
|
||||||
this.props.onHide();
|
|
||||||
}}>
|
|
||||||
Launch
|
Launch
|
||||||
</Button>
|
</Button>
|
||||||
</FlexRow>
|
</FlexRow>
|
||||||
@@ -117,6 +119,8 @@ class JSEmulatorLauncherSheet extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
|
export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
|
||||||
() => ({}),
|
({settingsState}) => ({
|
||||||
{},
|
settings: settingsState,
|
||||||
|
}),
|
||||||
|
{updateSettings},
|
||||||
)(JSEmulatorLauncherSheet);
|
)(JSEmulatorLauncherSheet);
|
||||||
|
|||||||
@@ -24,6 +24,13 @@ export type Settings = {
|
|||||||
* of Flipper.
|
* of Flipper.
|
||||||
*/
|
*/
|
||||||
enablePrefetching: Tristate;
|
enablePrefetching: Tristate;
|
||||||
|
jsApps: {
|
||||||
|
webAppLauncher: {
|
||||||
|
url: string;
|
||||||
|
height: number;
|
||||||
|
width: number;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Action =
|
export type Action =
|
||||||
@@ -37,6 +44,13 @@ const initialState: Settings = {
|
|||||||
androidHome: '/opt/android_sdk',
|
androidHome: '/opt/android_sdk',
|
||||||
enableAndroid: true,
|
enableAndroid: true,
|
||||||
enablePrefetching: Tristate.Unset,
|
enablePrefetching: Tristate.Unset,
|
||||||
|
jsApps: {
|
||||||
|
webAppLauncher: {
|
||||||
|
url: 'http://localhost:8888',
|
||||||
|
height: 600,
|
||||||
|
width: 800,
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function reducer(
|
export default function reducer(
|
||||||
|
|||||||
Reference in New Issue
Block a user