From e7fdd8332d434c15894d4cf7b3f849f3166cb93b Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Mon, 21 Sep 2020 11:50:45 -0700 Subject: [PATCH] Made sidebars toggleable Summary: Implemented a first button: make main menu collapsible. Also introduced some additional utilities and hooked up startup performance logging Reviewed By: cekkaewnumchai Differential Revision: D23783500 fbshipit-source-id: 2456fd781a52d497facbaccfabe885e4f8c408c5 --- desktop/app/src/App.tsx | 57 ++++++++++---------- desktop/app/src/sandy-chrome/LeftRail.tsx | 59 +++++++++++++++------ desktop/app/src/sandy-chrome/SandyApp.tsx | 35 +++++++++--- desktop/app/src/sandy-chrome/SandyIcons.tsx | 4 +- desktop/app/src/utils/useStore.tsx | 35 ++++++++++++ 5 files changed, 136 insertions(+), 54 deletions(-) create mode 100644 desktop/app/src/utils/useStore.tsx diff --git a/desktop/app/src/App.tsx b/desktop/app/src/App.tsx index ec8f0d4ae..367db78d1 100644 --- a/desktop/app/src/App.tsx +++ b/desktop/app/src/App.tsx @@ -79,37 +79,36 @@ const PluginContent = styled(FlexRow)({ PluginContent.displayName = 'App:PluginContent'; type Props = StateFromProps & OwnProps & DispatchProps; +export function registerStartupTime(logger: Logger) { + // track time since launch + const [s, ns] = process.hrtime(); + const launchEndTime = s * 1e3 + ns / 1e6; + ipcRenderer.on('getLaunchTime', (_: any, launchStartTime: number) => { + logger.track('performance', 'launchTime', launchEndTime - launchStartTime); + + QuickPerformanceLogger.markerPoint( + FLIPPER_QPL_EVENTS.STARTUP, + 'launchStartTime', + undefined, + 0, + launchStartTime, + ); + + QuickPerformanceLogger.markerEnd( + FLIPPER_QPL_EVENTS.STARTUP, + QuickLogActionType.SUCCESS, + 0, + launchEndTime, + ); + }); + + ipcRenderer.send('getLaunchTime'); + ipcRenderer.send('componentDidMount'); +} + export class App extends React.Component { componentDidMount() { - // track time since launch - const [s, ns] = process.hrtime(); - const launchEndTime = s * 1e3 + ns / 1e6; - ipcRenderer.on('getLaunchTime', (_: any, launchStartTime: number) => { - this.props.logger.track( - 'performance', - 'launchTime', - launchEndTime - launchStartTime, - ); - - QuickPerformanceLogger.markerPoint( - FLIPPER_QPL_EVENTS.STARTUP, - 'launchStartTime', - undefined, - 0, - launchStartTime, - ); - - QuickPerformanceLogger.markerEnd( - FLIPPER_QPL_EVENTS.STARTUP, - QuickLogActionType.SUCCESS, - 0, - launchEndTime, - ); - }); - - ipcRenderer.send('getLaunchTime'); - ipcRenderer.send('componentDidMount'); - + registerStartupTime(this.props.logger); if (hasNewChangesToShow(window.localStorage)) { this.props.setActiveSheet(ACTIVE_SHEET_CHANGELOG_RECENT_ONLY); } diff --git a/desktop/app/src/sandy-chrome/LeftRail.tsx b/desktop/app/src/sandy-chrome/LeftRail.tsx index 45a74d3b9..4b660bc73 100644 --- a/desktop/app/src/sandy-chrome/LeftRail.tsx +++ b/desktop/app/src/sandy-chrome/LeftRail.tsx @@ -22,8 +22,12 @@ import { MedicineBoxOutlined, } from '@ant-design/icons'; import {SidebarLeft, SidebarRight} from './SandyIcons'; +import {useDispatch, useStore} from '../utils/useStore'; +import {toggleLeftSidebarVisible} from '../reducers/application'; +import {theme} from './theme'; const LeftRailContainer = styled(FlexColumn)({ + background: theme.backgroundDefault, width: 48, boxShadow: 'inset -1px 0px 0px rgba(0, 0, 0, 0.1)', justifyContent: 'space-between', @@ -36,10 +40,10 @@ const LeftRailSection = styled(FlexColumn)({ }); LeftRailSection.displayName = 'LeftRailSection'; -const LeftRailButtonElem = styled(Button)<{margin: number}>(({margin}) => ({ - width: 36, - height: 36, - margin, +const LeftRailButtonElem = styled(Button)<{kind?: 'small'}>(({kind}) => ({ + width: kind === 'small' ? 32 : 36, + height: kind === 'small' ? 32 : 36, + margin: 6, padding: '5px 0', border: 'none', boxShadow: 'none', @@ -49,15 +53,19 @@ LeftRailButtonElem.displayName = 'LeftRailButtonElem'; function LeftRailButton({ icon, small, - active, + selected, + toggled, count, title, + onClick, }: { icon?: React.ReactElement; small?: boolean; - active?: boolean; + toggled?: boolean; + selected?: boolean; count?: number; title: string; + onClick?: React.MouseEventHandler; }) { let iconElement = icon && cloneElement(icon, {style: {fontSize: small ? 16 : 24}}); @@ -67,9 +75,14 @@ function LeftRailButton({ return ( ); @@ -86,7 +99,7 @@ export function LeftRail() { return ( - } active title="App Inspect" /> + } title="App Inspect" /> } title="Plugin Manager" /> } + icon={} small title="Right Sidebar Toggle" /> - } - small - title="Left Sidebar Toggle" - /> + } title="Log In" /> ); } + +function LeftSidebarToggleButton() { + const mainMenuVisible = useStore( + (state) => state.application.leftSidebarVisible, + ); + + const dispatch = useDispatch(); + + return ( + } + small + title="Left Sidebar Toggle" + toggled={mainMenuVisible} + onClick={() => { + dispatch(toggleLeftSidebarVisible()); + }} + /> + ); +} diff --git a/desktop/app/src/sandy-chrome/SandyApp.tsx b/desktop/app/src/sandy-chrome/SandyApp.tsx index b73f34f0f..2a3f99be7 100644 --- a/desktop/app/src/sandy-chrome/SandyApp.tsx +++ b/desktop/app/src/sandy-chrome/SandyApp.tsx @@ -7,23 +7,40 @@ * @format */ -import React from 'react'; +import React, {useEffect} from 'react'; import {styled} from 'flipper'; import {DatePicker} from 'antd'; import {Layout, FlexRow} from '../ui'; import {theme} from './theme'; +import {Logger} from '../fb-interfaces/Logger'; import {LeftRail} from './LeftRail'; import {TemporarilyTitlebar} from './TemporarilyTitlebar'; +import {registerStartupTime} from '../App'; +import {useStore} from '../utils/useStore'; + +export function SandyApp({logger}: {logger: Logger}) { + useEffect(() => { + registerStartupTime(logger); + // don't warn about logger, even with a new logger we don't want to re-register + // eslint-disable-next-line + }, []); + + const mainMenuVisible = useStore( + (state) => state.application.leftSidebarVisible, + ); -export function SandyApp() { return ( - - + + -
LeftMenu
+ {mainMenuVisible && ( +
LeftMenu
+ )}
@@ -44,11 +61,13 @@ export function SandyApp() { ); } -const LeftMenu = styled(FlexRow)({ - boxShadow: `inset -1px 0px 0px ${theme.dividerColor}`, +const LeftMenu = styled(FlexRow)<{collapsed: boolean}>(({collapsed}) => ({ + background: theme.backgroundWash, + boxShadow: collapsed ? undefined : `1px 0px 0px ${theme.dividerColor}`, + paddingRight: collapsed ? theme.space.middle : 0, height: '100%', width: '100%', -}); +})); const MainContainer = styled('div')({ display: 'flex', diff --git a/desktop/app/src/sandy-chrome/SandyIcons.tsx b/desktop/app/src/sandy-chrome/SandyIcons.tsx index 693bdc11f..d54504539 100644 --- a/desktop/app/src/sandy-chrome/SandyIcons.tsx +++ b/desktop/app/src/sandy-chrome/SandyIcons.tsx @@ -9,7 +9,7 @@ import React from 'react'; -export const SidebarLeft = (props: React.SVGProps) => ( +export const SidebarRight = (props: React.SVGProps) => ( ) => ( ); -export const SidebarRight = (props: React.SVGProps) => ( +export const SidebarLeft = (props: React.SVGProps) => ( ( + selector: (state: State) => Selected, + equalityFn: (left: Selected, right: Selected) => boolean = shallowEqual, +): Selected { + return useSelector(selector, equalityFn); +} + +/** + * Strongly typed useDispatch wrapper for the Flipper redux store. + */ +export function useDispatch(): Dispatch { + return useDispatchBase(); +}