Only show left sidebar toggle if there is a sidebar

Summary:
^

Not all selections have a left sidebar. If the current selection doesn't have one, it doesn't make sense to have the toggle sidebar button, so hide it.

Reviewed By: LukeDefeo

Differential Revision: D47593545

fbshipit-source-id: 940d59536e26bd1ab341d2038df431c67e0a5442
This commit is contained in:
Lorenzo Blasa
2023-07-20 04:48:20 -07:00
committed by Facebook GitHub Bot
parent 459f16022e
commit f566fed761
3 changed files with 30 additions and 11 deletions

View File

@@ -37,6 +37,7 @@ export type ShareType = {
} & SubShareType; } & SubShareType;
export type State = { export type State = {
hasLeftSidebar: boolean;
leftSidebarVisible: boolean; leftSidebarVisible: boolean;
rightSidebarVisible: boolean; rightSidebarVisible: boolean;
rightSidebarAvailable: boolean; rightSidebarAvailable: boolean;
@@ -48,6 +49,7 @@ export type State = {
}; };
type BooleanActionType = type BooleanActionType =
| 'hasLeftSidebar'
| 'leftSidebarVisible' | 'leftSidebarVisible'
| 'rightSidebarVisible' | 'rightSidebarVisible'
| 'rightSidebarAvailable'; | 'rightSidebarAvailable';
@@ -78,6 +80,7 @@ export type Action =
}; };
export const initialState: () => State = () => ({ export const initialState: () => State = () => ({
hasLeftSidebar: true,
leftSidebarVisible: true, leftSidebarVisible: true,
rightSidebarVisible: true, rightSidebarVisible: true,
rightSidebarAvailable: false, rightSidebarAvailable: false,
@@ -110,6 +113,7 @@ export default function reducer(
): State { ): State {
state = state || initialState(); state = state || initialState();
if ( if (
action.type === 'hasLeftSidebar' ||
action.type === 'leftSidebarVisible' || action.type === 'leftSidebarVisible' ||
action.type === 'rightSidebarVisible' || action.type === 'rightSidebarVisible' ||
action.type === 'rightSidebarAvailable' action.type === 'rightSidebarAvailable'
@@ -175,6 +179,11 @@ export const toggleLeftSidebarVisible = (payload?: boolean): Action => ({
payload, payload,
}); });
export const toggleHasLeftSidebar = (payload?: boolean): Action => ({
type: 'hasLeftSidebar',
payload,
});
export const toggleRightSidebarVisible = (payload?: boolean): Action => ({ export const toggleRightSidebarVisible = (payload?: boolean): Action => ({
type: 'rightSidebarVisible', type: 'rightSidebarVisible',
payload, payload,

View File

@@ -246,20 +246,25 @@ function NotificationButton({
function LeftSidebarToggleButton() { function LeftSidebarToggleButton() {
const dispatch = useDispatch(); const dispatch = useDispatch();
const hasMainMenu = useStore((state) => state.application.hasLeftSidebar);
const mainMenuVisible = useStore( const mainMenuVisible = useStore(
(state) => state.application.leftSidebarVisible, (state) => state.application.leftSidebarVisible,
); );
return ( if (hasMainMenu) {
<NavbarButton return (
label="Toggle Sidebar" <NavbarButton
icon={LayoutOutlined} label="Toggle Sidebar"
toggled={!mainMenuVisible} icon={LayoutOutlined}
onClick={() => { toggled={!mainMenuVisible}
dispatch(toggleLeftSidebarVisible()); onClick={() => {
}} dispatch(toggleLeftSidebarVisible());
/> }}
); />
);
}
return null;
} }
function RightSidebarToggleButton() { function RightSidebarToggleButton() {

View File

@@ -24,7 +24,10 @@ import {Navbar} from './Navbar';
import {useStore, useDispatch} from '../utils/useStore'; import {useStore, useDispatch} from '../utils/useStore';
import {FlipperDevTools} from '../chrome/FlipperDevTools'; import {FlipperDevTools} from '../chrome/FlipperDevTools';
import {setStaticView} from '../reducers/connections'; import {setStaticView} from '../reducers/connections';
import {toggleLeftSidebarVisible} from '../reducers/application'; import {
toggleHasLeftSidebar,
toggleLeftSidebarVisible,
} from '../reducers/application';
import {AppInspect} from './appinspect/AppInspect'; import {AppInspect} from './appinspect/AppInspect';
import PluginContainer from '../PluginContainer'; import PluginContainer from '../PluginContainer';
import {ContentContainer} from './ContentContainer'; import {ContentContainer} from './ContentContainer';
@@ -79,6 +82,8 @@ export function SandyApp() {
// toggle sidebar visibility if needed // toggle sidebar visibility if needed
const hasLeftSidebar = const hasLeftSidebar =
newSelection === 'appinspect' || newSelection === 'notification'; newSelection === 'appinspect' || newSelection === 'notification';
dispatch(toggleHasLeftSidebar(hasLeftSidebar));
if (hasLeftSidebar) { if (hasLeftSidebar) {
if (newSelection === toplevelSelection) { if (newSelection === toplevelSelection) {
dispatch(toggleLeftSidebarVisible()); dispatch(toggleLeftSidebarVisible());