Add settings UI

Summary:
Adds a simple UI for editing settings, a reducer and persistance config for the data.
These values aren't yet used for anything.

Reviewed By: passy

Differential Revision: D17684490

fbshipit-source-id: e76ac43ffa17d3606e59f4a1ccb940e8d9fbd9e8
This commit is contained in:
John Knox
2019-10-07 08:49:05 -07:00
committed by Facebook Github Bot
parent 8c15547597
commit eb64ff0832
8 changed files with 249 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ export const ACTIVE_SHEET_SELECT_PLUGINS_TO_EXPORT: 'SELECT_PLUGINS_TO_EXPORT' =
'SELECT_PLUGINS_TO_EXPORT';
export const ACTIVE_SHEET_SHARE_DATA: 'SHARE_DATA' = 'SHARE_DATA';
export const ACTIVE_SHEET_SIGN_IN: 'SIGN_IN' = 'SIGN_IN';
export const ACTIVE_SHEET_SETTINGS: 'SETTINGS' = 'SETTINGS';
export const ACTIVE_SHEET_SHARE_DATA_IN_FILE: 'SHARE_DATA_IN_FILE' =
'SHARE_DATA_IN_FILE';
export const SET_EXPORT_STATUS_MESSAGE: 'SET_EXPORT_STATUS_MESSAGE' =
@@ -29,6 +30,7 @@ export type ActiveSheet =
| typeof ACTIVE_SHEET_PLUGINS
| typeof ACTIVE_SHEET_SHARE_DATA
| typeof ACTIVE_SHEET_SIGN_IN
| typeof ACTIVE_SHEET_SETTINGS
| typeof ACTIVE_SHEET_SHARE_DATA_IN_FILE
| typeof ACTIVE_SHEET_SELECT_PLUGINS_TO_EXPORT
| null;

View File

@@ -26,6 +26,10 @@ import plugins, {
State as PluginsState,
Action as PluginsAction,
} from './plugins';
import settings, {
State as SettingsState,
Action as SettingsAction,
} from './settings';
import user, {State as UserState, Action as UserAction} from './user';
import {persistReducer, PersistPartial} from 'redux-persist';
@@ -41,6 +45,7 @@ export type Actions =
| NotificationsAction
| PluginsAction
| UserAction
| SettingsAction
| {type: 'INIT'};
export type State = {
@@ -50,6 +55,7 @@ export type State = {
notifications: NotificationsState & PersistPartial;
plugins: PluginsState;
user: UserState & PersistPartial;
settingsState: SettingsState & PersistPartial;
};
export type Store = ReduxStore<State, Actions>;
@@ -94,4 +100,8 @@ export default combineReducers<State, Actions>({
},
user,
),
settingsState: persistReducer(
{key: 'settings', storage, whitelist: ['settings']},
settings,
),
});

49
src/reducers/settings.tsx Normal file
View File

@@ -0,0 +1,49 @@
/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
import {Actions} from './index';
export type Settings = {
androidHome: string;
};
export type State = {
settings: Settings;
};
export type Action =
| {type: 'INIT'}
| {
type: 'UPDATE_SETTINGS';
payload: Settings;
};
const initialState: State = {
settings: {
androidHome: '/opt/android_sdk',
},
};
export default function reducer(
state: State = initialState,
action: Actions,
): State {
if (action.type === 'UPDATE_SETTINGS') {
return {
...state,
settings: action.payload,
};
}
return state;
}
export function updateSettings(settings: Settings): Action {
return {
type: 'UPDATE_SETTINGS',
payload: settings,
};
}