63a2430a7c
## Issue 1709 - If you sign in while reporting, you end up in the homepage ## Notes The other option is to just make `<Header>` always redirect back to where it came from using the full path. But existing code elsewhere seem to always trim off any params (e.g. `location.search`, `location.hash`) when doing redirects. So, ended up making it generic and let the caller decide where to redirect (and with what params).
167 lines
5.1 KiB
JavaScript
167 lines
5.1 KiB
JavaScript
// @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, useIsMobileLandscape } from 'effects/use-screensize';
|
|
import classnames from 'classnames';
|
|
import Header from 'component/header';
|
|
import React from 'react';
|
|
import Wallpaper from 'component/wallpaper';
|
|
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,
|
|
authRedirect?: string, // Redirects to '/' by default.
|
|
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<Node>,
|
|
className: ?string,
|
|
filePage: boolean,
|
|
fullWidthPage: boolean,
|
|
isMarkdown?: boolean,
|
|
livestream?: boolean,
|
|
noFooter: boolean,
|
|
noHeader: boolean,
|
|
noSideNavigation: boolean,
|
|
rightSide?: Node,
|
|
settingsPage?: boolean,
|
|
renderMode: String,
|
|
videoTheaterMode: boolean,
|
|
isPopoutWindow?: boolean,
|
|
};
|
|
|
|
function Page(props: Props) {
|
|
const {
|
|
authPage = false,
|
|
authRedirect,
|
|
backout,
|
|
chatDisabled,
|
|
children,
|
|
className,
|
|
filePage = false,
|
|
fullWidthPage = false,
|
|
isMarkdown = false,
|
|
livestream,
|
|
noFooter = false,
|
|
noHeader = false,
|
|
noSideNavigation = false,
|
|
rightSide,
|
|
settingsPage,
|
|
renderMode,
|
|
videoTheaterMode,
|
|
isPopoutWindow,
|
|
} = props;
|
|
|
|
const {
|
|
location: { pathname },
|
|
} = useHistory();
|
|
|
|
const theaterMode = renderMode === 'video' || renderMode === 'audio' ? videoTheaterMode : false;
|
|
const isMediumScreen = useIsMediumScreen();
|
|
const isMobile = useIsMobile();
|
|
const isLandscapeRotated = useIsMobileLandscape();
|
|
const [sidebarOpen, setSidebarOpen] = usePersistedState('sidebar', false);
|
|
|
|
const url = pathname.slice(1).replace(/:/g, '#');
|
|
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
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [isOnFilePage, isMediumScreen]);
|
|
|
|
return (
|
|
<>
|
|
<Wallpaper uri={url} />
|
|
{!noHeader && (
|
|
<Header
|
|
authHeader={authPage}
|
|
authRedirect={authRedirect}
|
|
backout={backout}
|
|
sidebarOpen={sidebarOpen}
|
|
isAbsoluteSideNavHidden={isAbsoluteSideNavHidden}
|
|
setSidebarOpen={setSidebarOpen}
|
|
/>
|
|
)}
|
|
|
|
<div
|
|
className={classnames('main-wrapper__inner', {
|
|
'main-wrapper__inner--filepage': isOnFilePage,
|
|
'main-wrapper__inner--theater-mode': isOnFilePage && theaterMode && !isMobile,
|
|
'main-wrapper__inner--auth': authPage,
|
|
'main--popout-chat': isPopoutWindow,
|
|
})}
|
|
>
|
|
{!authPage &&
|
|
(settingsPage ? (
|
|
<SettingsSideNavigation />
|
|
) : (
|
|
!noSideNavigation && (
|
|
<SideNavigation
|
|
sidebarOpen={sidebarOpen}
|
|
setSidebarOpen={setSidebarOpen}
|
|
isMediumScreen={isMediumScreen}
|
|
isOnFilePage={isOnFilePage}
|
|
/>
|
|
)
|
|
))}
|
|
|
|
<div
|
|
className={classnames({
|
|
'sidebar--pusher': fullWidthPage,
|
|
'sidebar--pusher--open': sidebarOpen && fullWidthPage,
|
|
'sidebar--pusher--filepage': !fullWidthPage,
|
|
})}
|
|
>
|
|
<main
|
|
id={'main-content'}
|
|
className={classnames(MAIN_CLASS, className, {
|
|
'main--full-width': fullWidthPage,
|
|
'main--auth-page': authPage,
|
|
'main--file-page': filePage,
|
|
'main--video-page': filePage && !theaterMode && !livestream && !isMarkdown,
|
|
'main--settings-page': settingsPage,
|
|
'main--markdown': isMarkdown,
|
|
'main--theater-mode': isOnFilePage && theaterMode && !livestream && !isMarkdown && !isMobile,
|
|
'main--livestream': livestream && !chatDisabled,
|
|
'main--popout-chat': isPopoutWindow,
|
|
})}
|
|
>
|
|
{children}
|
|
|
|
{(!isMobile || isLandscapeRotated) && (!livestream || !chatDisabled) && rightSide}
|
|
</main>
|
|
|
|
{!noFooter && (
|
|
<React.Suspense fallback={null}>
|
|
<Footer />
|
|
</React.Suspense>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default Page;
|