// @flow import { lazyImport } from 'util/lazyImport'; import { MAIN_CLASS } from 'constants/classnames'; import { parseURI } from 'util/lbryURI'; import { useHistory } from 'react-router'; import { useIsMobile, useIsMediumScreen } from 'effects/use-screensize'; import classnames from 'classnames'; import Header from 'component/header'; import React from 'react'; import SettingsSideNavigation from 'component/settingsSideNavigation'; import SideNavigation from 'component/sideNavigation'; import type { Node } from 'react'; import usePersistedState from 'effects/use-persisted-state'; const Footer = lazyImport(() => import('web/component/footer' /* webpackChunkName: "footer" */)); type Props = { authPage: boolean, backout: { backLabel?: string, backNavDefault?: string, title: string, simpleTitle: string, // Just use the same value as `title` if `title` is already short (~< 10 chars), unless you have a better idea for title overlfow on mobile }, chatDisabled: boolean, children: Node | Array, className: ?string, filePage: boolean, fullWidthPage: boolean, isMarkdown?: boolean, livestream?: boolean, noFooter: boolean, noHeader: boolean, noSideNavigation: boolean, rightSide?: Node, settingsPage?: boolean, videoTheaterMode: boolean, isPopoutWindow?: boolean, }; function Page(props: Props) { const { authPage = false, backout, chatDisabled, children, className, filePage = false, fullWidthPage = false, isMarkdown = false, livestream, noFooter = false, noHeader = false, noSideNavigation = false, rightSide, settingsPage, videoTheaterMode, isPopoutWindow, } = props; const { location: { pathname }, } = useHistory(); const isMediumScreen = useIsMediumScreen(); const isMobile = useIsMobile(); const [sidebarOpen, setSidebarOpen] = usePersistedState('sidebar', false); let isOnFilePage = false; try { const url = pathname.slice(1).replace(/:/g, '#'); const { isChannel } = parseURI(url); if (!isChannel) isOnFilePage = true; } catch (e) {} const isAbsoluteSideNavHidden = (isOnFilePage || isMobile) && !sidebarOpen; React.useEffect(() => { if (isOnFilePage || isMediumScreen) setSidebarOpen(false); // TODO: make sure setState callback for usePersistedState uses useCallback to it doesn't cause effect to re-run }, [isOnFilePage, isMediumScreen, setSidebarOpen]); return ( <> {!noHeader && (
)}
{!authPage && (settingsPage ? ( ) : ( !noSideNavigation && ( ) ))}
{children} {!isMobile && rightSide && (!livestream || !chatDisabled) && (
{rightSide}
)}
{!noFooter && (
); } export default Page;