export function SandyApp()

in desktop/flipper-ui-core/src/sandy-chrome/SandyApp.tsx [55:200]


export function SandyApp() {
  const logger = useLogger();
  const dispatch = useDispatch();
  const leftSidebarVisible = useStore(
    (state) => state.application.leftSidebarVisible,
  );
  const staticView = useStore((state) => state.connections.staticView);

  /**
   * top level navigation uses two pieces of state, selection stored here, and selection that is based on what is stored in the reducer (which might be influenced by redux action dispatches to different means).
   * The logic here is to sync both, but without modifying the navigation related reducers to not break classic Flipper.
   * It is possible to simplify this in the future.
   */
  const [toplevelSelection, setStoredToplevelSelection] =
    useState<ToplevelNavItem>('appinspect');

  // Handle toplevel nav clicks from LeftRail
  const setToplevelSelection = useCallback(
    (newSelection: ToplevelNavItem) => {
      // toggle sidebar visibility if needed
      const hasLeftSidebar =
        newSelection === 'appinspect' || newSelection === 'notification';
      if (hasLeftSidebar) {
        if (newSelection === toplevelSelection) {
          dispatch(toggleLeftSidebarVisible());
        } else {
          dispatch(toggleLeftSidebarVisible(true));
        }
      }
      switch (newSelection) {
        case 'flipperlogs':
          dispatch(setStaticView(FlipperDevTools));
          break;
        default:
      }
      setStoredToplevelSelection(newSelection);
    },
    [dispatch, toplevelSelection],
  );

  useEffect(() => {
    document.title = `Flipper (${getVersionString()}${
      config.isFBBuild ? '@FB' : ''
    })`;

    registerStartupTime(logger);

    if (hasPlatformWizardBeenDone(window.localStorage)) {
      Dialog.showModal((onHide) => (
        <PlatformSelectWizard
          onHide={onHide}
          platform={
            getRenderHostInstance().serverConfig.environmentInfo.os.platform
          }
        />
      ));
    }

    showChangelog(true);

    // don't warn about logger, even with a new logger we don't want to re-register
    // eslint-disable-next-line
  }, []);

  useEffect(() => {
    if (fbConfig.warnFBEmployees && isProduction()) {
      isFBEmployee()
        .then((isEmployee) => {
          if (isEmployee) {
            notification.warning({
              placement: 'bottomLeft',
              message: 'Please use Flipper@FB',
              description: (
                <>
                  You are using the open-source version of Flipper. Install the
                  internal build from{' '}
                  <Link href="munki://detail-Flipper">
                    Managed Software Center
                  </Link>{' '}
                  to get access to more plugins.
                </>
              ),
              duration: null,
            });
          }
        })
        .catch((e) => {
          console.warn('Failed to check if user is employee', e);
        });
    }
  }, []);

  const leftMenuContent = !leftSidebarVisible ? null : toplevelSelection ===
    'appinspect' ? (
    <AppInspect />
  ) : toplevelSelection === 'notification' ? (
    <Notification />
  ) : null;

  return (
    <RootElement>
      <Layout.Bottom>
        <Layout.Left>
          <Layout.Horizontal>
            <LeftRail
              toplevelSelection={toplevelSelection}
              setToplevelSelection={setToplevelSelection}
            />
            <_Sidebar width={250} minWidth={220} maxWidth={800} gutter>
              {leftMenuContent && (
                <TrackingScope scope={toplevelSelection!}>
                  {leftMenuContent}
                </TrackingScope>
              )}
            </_Sidebar>
          </Layout.Horizontal>
          <MainContainer>
            {staticView ? (
              <TrackingScope
                scope={
                  (staticView as any).displayName ??
                  staticView.name ??
                  staticView.constructor?.name ??
                  'unknown static view'
                }>
                {staticView === WelcomeScreenStaticView ? (
                  React.createElement(staticView) /* avoid shadow */
                ) : (
                  <ContentContainer>
                    {React.createElement(staticView, {
                      logger: logger,
                    })}
                  </ContentContainer>
                )}
              </TrackingScope>
            ) : (
              <PluginContainer logger={logger} />
            )}
            {outOfContentsContainer}
          </MainContainer>
        </Layout.Left>
        <_PortalsManager />
      </Layout.Bottom>
    </RootElement>
  );
}