Top level selection moved to reducer
Summary: Intention of this change is to simplify and standardise the way top level selection is done. Top level selection is now part of the state, and thus setting it is done in the reducer instead. Reviewed By: antonk52 Differential Revision: D47844742 fbshipit-source-id: 8e5aad8975f0046b85098b988cca40228316c249
This commit is contained in:
committed by
Facebook GitHub Bot
parent
63ed9d7324
commit
b1b056485c
@@ -11,6 +11,13 @@ import {v1 as uuidv1} from 'uuid';
|
||||
import {getRenderHostInstance} from 'flipper-frontend-core';
|
||||
import {Actions} from './';
|
||||
|
||||
export type ToplevelNavigationItem =
|
||||
| 'appinspect'
|
||||
| 'flipperlogs'
|
||||
| 'notification'
|
||||
| 'connectivity'
|
||||
| undefined;
|
||||
|
||||
export type LauncherMsg = {
|
||||
message: string;
|
||||
severity: 'warning' | 'error';
|
||||
@@ -37,6 +44,7 @@ export type ShareType = {
|
||||
} & SubShareType;
|
||||
|
||||
export type State = {
|
||||
topLevelSelection: ToplevelNavigationItem;
|
||||
hasLeftSidebar: boolean;
|
||||
leftSidebarVisible: boolean;
|
||||
rightSidebarVisible: boolean;
|
||||
@@ -59,6 +67,10 @@ export type Action =
|
||||
type: BooleanActionType;
|
||||
payload?: boolean;
|
||||
}
|
||||
| {
|
||||
type: 'topLevelSelection';
|
||||
payload: ToplevelNavigationItem;
|
||||
}
|
||||
| {
|
||||
type: 'windowIsFocused';
|
||||
payload: {isFocused: boolean; time: number};
|
||||
@@ -80,6 +92,7 @@ export type Action =
|
||||
};
|
||||
|
||||
export const initialState: () => State = () => ({
|
||||
topLevelSelection: 'appinspect',
|
||||
hasLeftSidebar: true,
|
||||
leftSidebarVisible: true,
|
||||
rightSidebarVisible: true,
|
||||
@@ -132,6 +145,19 @@ export default function reducer(
|
||||
[action.type]: newValue,
|
||||
};
|
||||
}
|
||||
} else if (action.type === 'topLevelSelection') {
|
||||
const topLevelSelection = action.payload;
|
||||
|
||||
const hasLeftSidebar =
|
||||
topLevelSelection === 'appinspect' ||
|
||||
topLevelSelection === 'notification';
|
||||
|
||||
return {
|
||||
...state,
|
||||
leftSidebarVisible: hasLeftSidebar,
|
||||
hasLeftSidebar,
|
||||
topLevelSelection,
|
||||
};
|
||||
} else if (action.type === 'windowIsFocused') {
|
||||
return {
|
||||
...state,
|
||||
@@ -174,6 +200,13 @@ export const toggleAction = (
|
||||
payload,
|
||||
});
|
||||
|
||||
export const setTopLevelSelection = (
|
||||
payload: ToplevelNavigationItem,
|
||||
): Action => ({
|
||||
type: 'topLevelSelection',
|
||||
payload,
|
||||
});
|
||||
|
||||
export const toggleLeftSidebarVisible = (payload?: boolean): Action => ({
|
||||
type: 'leftSidebarVisible',
|
||||
payload,
|
||||
|
||||
@@ -161,13 +161,12 @@ export type Action =
|
||||
}
|
||||
| RegisterPluginAction;
|
||||
|
||||
const DEFAULT_PLUGIN = 'DeviceLogs';
|
||||
const DEFAULT_DEVICE_BLACKLIST: DeviceOS[] = ['MacOS', 'Metro', 'Windows'];
|
||||
const INITAL_STATE: State = {
|
||||
devices: [],
|
||||
selectedDevice: null,
|
||||
selectedAppId: null,
|
||||
selectedPlugin: DEFAULT_PLUGIN,
|
||||
selectedPlugin: null,
|
||||
pluginMenuEntries: [],
|
||||
userPreferredDevice: null,
|
||||
userPreferredPlugin: null,
|
||||
|
||||
Reference in New Issue
Block a user