2018-03-26 23:32:43 +02:00
// @flow
2021-07-07 09:10:28 +02:00
import { lazyImport } from 'util/lazyImport' ;
2022-01-14 21:24:16 +01:00
import { MAIN _CLASS } from 'constants/classnames' ;
import { parseURI } from 'util/lbryURI' ;
2020-08-10 22:47:39 +02:00
import { useHistory } from 'react-router' ;
2022-04-06 14:01:29 +02:00
import { useIsMobile , useIsMediumScreen , useIsMobileLandscape } from 'effects/use-screensize' ;
2022-01-14 21:24:16 +01:00
import classnames from 'classnames' ;
import Header from 'component/header' ;
import React from 'react' ;
2022-02-11 19:50:55 +01:00
import Wallpaper from 'component/wallpaper' ;
2022-01-14 21:24:16 +01:00
import SettingsSideNavigation from 'component/settingsSideNavigation' ;
import SideNavigation from 'component/sideNavigation' ;
import type { Node } from 'react' ;
import usePersistedState from 'effects/use-persisted-state' ;
2018-03-26 23:32:43 +02:00
2021-10-26 08:15:08 +02:00
const Footer = lazyImport ( ( ) => import ( 'web/component/footer' /* webpackChunkName: "footer" */ ) ) ;
2021-06-11 08:06:29 +02:00
2018-03-26 23:32:43 +02:00
type Props = {
2019-10-28 15:04:37 +01:00
authPage : boolean ,
2022-06-22 15:07:15 +02:00
authRedirect ? : string , // Redirects to '/' by default.
2020-07-10 23:04:36 +02:00
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
} ,
2022-01-14 21:24:16 +01:00
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 ,
2022-04-20 10:20:15 +02:00
renderMode : String ,
2022-01-14 21:24:16 +01:00
videoTheaterMode : boolean ,
isPopoutWindow ? : boolean ,
2018-03-26 23:32:43 +02:00
} ;
2019-06-17 22:32:38 +02:00
function Page ( props : Props ) {
2020-06-29 21:54:07 +02:00
const {
2022-01-14 21:24:16 +01:00
authPage = false ,
2022-06-22 15:07:15 +02:00
authRedirect ,
2022-01-14 21:24:16 +01:00
backout ,
chatDisabled ,
2020-06-29 21:54:07 +02:00
children ,
className ,
2020-08-10 22:47:39 +02:00
filePage = false ,
2020-08-21 17:49:13 +02:00
fullWidthPage = false ,
2021-03-12 17:18:09 +01:00
isMarkdown = false ,
2021-03-10 19:34:21 +01:00
livestream ,
2022-01-14 21:24:16 +01:00
noFooter = false ,
noHeader = false ,
noSideNavigation = false ,
2021-04-23 21:59:48 +02:00
rightSide ,
2022-01-14 21:24:16 +01:00
settingsPage ,
2022-04-20 10:20:15 +02:00
renderMode ,
2022-01-14 21:24:16 +01:00
videoTheaterMode ,
isPopoutWindow ,
2020-06-29 21:54:07 +02:00
} = props ;
2021-01-08 16:21:27 +01:00
2020-08-10 22:47:39 +02:00
const {
location : { pathname } ,
} = useHistory ( ) ;
2022-01-14 21:24:16 +01:00
2022-04-21 09:31:58 +02:00
const theaterMode = renderMode === 'video' || renderMode === 'audio' ? videoTheaterMode : false ;
2020-08-10 22:47:39 +02:00
const isMediumScreen = useIsMediumScreen ( ) ;
const isMobile = useIsMobile ( ) ;
2022-04-06 14:01:29 +02:00
const isLandscapeRotated = useIsMobileLandscape ( ) ;
2022-01-14 21:24:16 +01:00
const [ sidebarOpen , setSidebarOpen ] = usePersistedState ( 'sidebar' , false ) ;
2020-08-21 17:49:13 +02:00
2022-02-11 19:50:55 +01:00
const url = pathname . slice ( 1 ) . replace ( /:/g , '#' ) ;
2020-08-10 22:47:39 +02:00
let isOnFilePage = false ;
try {
const url = pathname . slice ( 1 ) . replace ( /:/g , '#' ) ;
const { isChannel } = parseURI ( url ) ;
2022-01-14 21:24:16 +01:00
if ( ! isChannel ) isOnFilePage = true ;
2020-08-10 22:47:39 +02:00
} catch ( e ) { }
const isAbsoluteSideNavHidden = ( isOnFilePage || isMobile ) && ! sidebarOpen ;
React . useEffect ( ( ) => {
2022-01-14 21:24:16 +01:00
if ( isOnFilePage || isMediumScreen ) setSidebarOpen ( false ) ;
2020-12-17 19:43:47 +01:00
// TODO: make sure setState callback for usePersistedState uses useCallback to it doesn't cause effect to re-run
2022-01-14 22:07:44 +01:00
// eslint-disable-next-line react-hooks/exhaustive-deps
} , [ isOnFilePage , isMediumScreen ] ) ;
2019-06-17 22:32:38 +02:00
2019-08-27 16:43:42 +02:00
return (
2022-01-14 21:24:16 +01:00
< >
2022-02-11 19:50:55 +01:00
< Wallpaper uri = { url } / >
2020-08-10 22:47:39 +02:00
{ ! noHeader && (
< Header
authHeader = { authPage }
2022-06-22 15:07:15 +02:00
authRedirect = { authRedirect }
2020-08-10 22:47:39 +02:00
backout = { backout }
sidebarOpen = { sidebarOpen }
isAbsoluteSideNavHidden = { isAbsoluteSideNavHidden }
setSidebarOpen = { setSidebarOpen }
/ >
) }
2022-01-14 21:24:16 +01:00
2021-01-08 16:21:27 +01:00
< div
className = { classnames ( 'main-wrapper__inner' , {
'main-wrapper__inner--filepage' : isOnFilePage ,
2022-04-20 10:20:15 +02:00
'main-wrapper__inner--theater-mode' : isOnFilePage && theaterMode && ! isMobile ,
2021-12-14 06:58:28 +01:00
'main-wrapper__inner--auth' : authPage ,
2022-01-14 21:24:16 +01:00
'main--popout-chat' : isPopoutWindow ,
2021-01-08 16:21:27 +01:00
} ) }
>
2022-01-14 21:24:16 +01:00
{ ! authPage &&
( settingsPage ? (
< SettingsSideNavigation / >
) : (
! noSideNavigation && (
< SideNavigation
sidebarOpen = { sidebarOpen }
setSidebarOpen = { setSidebarOpen }
isMediumScreen = { isMediumScreen }
isOnFilePage = { isOnFilePage }
/ >
)
) ) }
2021-08-19 03:36:43 +02:00
2021-12-11 15:59:32 +01:00
< div
className = { classnames ( {
'sidebar--pusher' : fullWidthPage ,
'sidebar--pusher--open' : sidebarOpen && fullWidthPage ,
'sidebar--pusher--filepage' : ! fullWidthPage ,
2020-08-21 17:49:13 +02:00
} ) }
2020-08-10 22:47:39 +02:00
>
2021-12-11 15:59:32 +01:00
< main
id = { 'main-content' }
className = { classnames ( MAIN _CLASS , className , {
2022-03-22 08:06:16 +01:00
'main--full-width' : fullWidthPage ,
2021-12-11 15:59:32 +01:00
'main--auth-page' : authPage ,
'main--file-page' : filePage ,
2022-04-20 10:20:15 +02:00
'main--video-page' : filePage && ! theaterMode && ! livestream && ! isMarkdown ,
2021-12-11 15:59:32 +01:00
'main--settings-page' : settingsPage ,
'main--markdown' : isMarkdown ,
2022-04-20 10:20:15 +02:00
'main--theater-mode' : isOnFilePage && theaterMode && ! livestream && ! isMarkdown && ! isMobile ,
2021-12-11 15:59:32 +01:00
'main--livestream' : livestream && ! chatDisabled ,
2022-01-14 21:24:16 +01:00
'main--popout-chat' : isPopoutWindow ,
2021-12-11 15:59:32 +01:00
} ) }
>
{ children }
2021-04-23 21:59:48 +02:00
2022-04-06 14:01:29 +02:00
{ ( ! isMobile || isLandscapeRotated ) && ( ! livestream || ! chatDisabled ) && rightSide }
2021-12-11 15:59:32 +01:00
< / main >
2022-01-14 21:24:16 +01:00
2021-12-11 15:59:32 +01:00
{ ! noFooter && (
< React.Suspense fallback = { null } >
< Footer / >
< / React.Suspense >
) }
< / div >
2019-08-27 16:43:42 +02:00
< / div >
2022-01-14 21:24:16 +01:00
< / >
2019-08-27 16:43:42 +02:00
) ;
2018-05-07 06:50:55 +02:00
}
2018-03-26 23:32:43 +02:00
export default Page ;