// @flow import type { Node } from 'react'; import * as PAGES from 'constants/pages'; import * as ICONS from 'constants/icons'; import * as KEYCODES from 'constants/keycodes'; import { SIDEBAR_SUBS_DISPLAYED } from 'constants/subscriptions'; import React from 'react'; import Button from 'component/button'; import ClaimPreviewTitle from 'component/claimPreviewTitle'; import classnames from 'classnames'; import Icon from 'component/common/icon'; import NotificationBubble from 'component/notificationBubble'; import DebouncedInput from 'component/common/debounced-input'; import I18nMessage from 'component/i18nMessage'; import ChannelThumbnail from 'component/channelThumbnail'; import { useIsMobile, useIsLargeScreen } from 'effects/use-screensize'; import { GetLinksData } from 'util/buildHomepage'; import { platform } from 'util/platform'; import { DOMAIN, ENABLE_UI_NOTIFICATIONS } from 'config'; import PremiumBadge from 'component/premiumBadge'; const touch = platform.isTouch(); type SideNavLink = { title: string, icon: string, link?: string, route?: string, onClick?: () => any, extra?: Node, hideForUnauth?: boolean, noI18n?: boolean, }; const getHomeButton = (additionalAction) => ({ title: 'Home', link: `/`, icon: ICONS.HOME, onClick: () => { if (window.location.pathname === '/') { window.scrollTo({ top: 0, left: 0, behavior: 'smooth' }); if (additionalAction) { additionalAction(); } } }, }); const RECENT_FROM_FOLLOWING = { title: 'Following --[sidebar button]--', link: `/$/${PAGES.CHANNELS_FOLLOWING}`, icon: ICONS.SUBSCRIBE, }; const NOTIFICATIONS: SideNavLink = { title: 'Notifications', link: `/$/${PAGES.NOTIFICATIONS}`, icon: ICONS.NOTIFICATION, extra: , hideForUnauth: true, }; const WATCH_LATER: SideNavLink = { title: 'Watch Later', link: `/$/${PAGES.LIST}/watchlater`, icon: ICONS.TIME, hideForUnauth: true, }; const FAVORITES: SideNavLink = { title: 'Favorites', link: `/$/${PAGES.LIST}/favorites`, icon: ICONS.STAR, hideForUnauth: true, }; const PLAYLISTS: SideNavLink = { title: 'Lists', link: `/$/${PAGES.LISTS}`, icon: ICONS.STACK, hideForUnauth: true, }; const WATCH_HISTORY: SideNavLink = { title: 'Watch History', link: `/$/${PAGES.WATCH_HISTORY}`, icon: ICONS.WATCH_HISTORY, hideForUnauth: true, }; const PREMIUM: SideNavLink = { title: 'Premium', link: `/$/${PAGES.ODYSEE_MEMBERSHIP}`, icon: ICONS.UPGRADE, hideForUnauth: true, noI18n: true, }; const UNAUTH_LINKS: Array = [ { title: 'Log In', link: `/$/${PAGES.AUTH_SIGNIN}`, icon: ICONS.SIGN_IN, }, { title: 'Sign Up', link: `/$/${PAGES.AUTH}`, icon: ICONS.SIGN_UP, }, { title: 'Settings', link: `/$/${PAGES.SETTINGS}`, icon: ICONS.SETTINGS, }, { title: 'Help', link: `/$/${PAGES.HELP}`, icon: ICONS.HELP, }, ]; // **************************************************************************** // **************************************************************************** type Props = { subscriptions: Array, lastActiveSubs: ?Array, followedTags: Array, email: ?string, uploadCount: number, doSignOut: () => void, sidebarOpen: boolean, setSidebarOpen: (boolean) => void, isMediumScreen: boolean, isOnFilePage: boolean, unseenCount: number, purchaseSuccess: boolean, doClearPurchasedUriSuccess: () => void, user: ?User, homepageData: any, doClearClaimSearch: () => void, odyseeMembership: ?string, doFetchLastActiveSubs: (force?: boolean, count?: number) => void, }; function SideNavigation(props: Props) { const { subscriptions, lastActiveSubs, doSignOut, email, purchaseSuccess, doClearPurchasedUriSuccess, sidebarOpen, setSidebarOpen, isMediumScreen, isOnFilePage, unseenCount, homepageData, user, followedTags, doClearClaimSearch, odyseeMembership, doFetchLastActiveSubs, } = props; const isLargeScreen = useIsLargeScreen(); const EXTRA_SIDEBAR_LINKS = GetLinksData(homepageData, isLargeScreen).map( ({ pinnedUrls, pinnedClaimIds, hideByDefault, ...theRest }) => theRest ); const MOBILE_PUBLISH: Array = [ { title: 'Go Live', link: `/$/${PAGES.LIVESTREAM}`, icon: ICONS.VIDEO, hideForUnauth: true, }, { title: 'Upload', link: `/$/${PAGES.UPLOAD}`, icon: ICONS.PUBLISH, hideForUnauth: true, }, { title: 'Post', link: `/$/${PAGES.POST}`, icon: ICONS.POST, hideForUnauth: true, }, ]; const MOBILE_LINKS: Array = [ { title: 'New Channel', link: `/$/${PAGES.CHANNEL_NEW}`, icon: ICONS.CHANNEL, hideForUnauth: true, }, { title: 'Sync YouTube Channel', link: `/$/${PAGES.YOUTUBE_SYNC}`, icon: ICONS.YOUTUBE, hideForUnauth: true, }, { title: 'Uploads', link: `/$/${PAGES.UPLOADS}`, icon: ICONS.PUBLISH, hideForUnauth: true, }, { title: 'Channels', link: `/$/${PAGES.CHANNELS}`, icon: ICONS.CHANNEL, hideForUnauth: true, }, { title: 'Creator Analytics', link: `/$/${PAGES.CREATOR_DASHBOARD}`, icon: ICONS.ANALYTICS, hideForUnauth: true, }, { title: 'Wallet', link: `/$/${PAGES.WALLET}`, icon: ICONS.WALLET, hideForUnauth: true, }, { title: 'Rewards', link: `/$/${PAGES.REWARDS}`, icon: ICONS.REWARDS, hideForUnauth: true, }, { title: 'Invites', link: `/$/${PAGES.INVITE}`, icon: ICONS.INVITE, hideForUnauth: true, }, { title: 'Settings', link: `/$/${PAGES.SETTINGS}`, icon: ICONS.SETTINGS, hideForUnauth: true, }, { title: 'Help', link: `/$/${PAGES.HELP}`, icon: ICONS.HELP, hideForUnauth: true, }, { title: 'Sign Out', onClick: doSignOut, icon: ICONS.SIGN_OUT, hideForUnauth: true, }, ]; const notificationsEnabled = ENABLE_UI_NOTIFICATIONS || (user && user.experimental_ui); const isAuthenticated = Boolean(email); const [pulseLibrary, setPulseLibrary] = React.useState(false); const [expandTags, setExpandTags] = React.useState(false); const isPersonalized = !IS_WEB || isAuthenticated; const isAbsolute = isOnFilePage || isMediumScreen; const isMobile = useIsMobile(); const [menuInitialized, setMenuInitialized] = React.useState(false); const menuCanCloseCompletely = (isOnFilePage && !isMobile) || (isMobile && menuInitialized); const hideMenuFromView = menuCanCloseCompletely && !sidebarOpen; const [canDisposeMenu, setCanDisposeMenu] = React.useState(false); React.useEffect(() => { if (hideMenuFromView || !menuInitialized) { const handler = setTimeout(() => { setMenuInitialized(true); setCanDisposeMenu(true); }, 250); return () => { clearTimeout(handler); }; } else { setCanDisposeMenu(false); } }, [hideMenuFromView, menuInitialized]); const shouldRenderLargeMenu = (menuCanCloseCompletely && !isAbsolute) || sidebarOpen; const showMicroMenu = !sidebarOpen && !menuCanCloseCompletely; const showPushMenu = sidebarOpen && !menuCanCloseCompletely; const showOverlay = isAbsolute && sidebarOpen; const showTagSection = sidebarOpen && isPersonalized && followedTags && followedTags.length; const [subscriptionFilter, setSubscriptionFilter] = React.useState(''); let displayedFollowedTags = followedTags; if (showTagSection && followedTags.length > SIDEBAR_SUBS_DISPLAYED && !expandTags) { displayedFollowedTags = followedTags.slice(0, SIDEBAR_SUBS_DISPLAYED); } function getLink(props: SideNavLink) { const { hideForUnauth, route, link, noI18n, ...passedProps } = props; const { title, icon, extra } = passedProps; if (hideForUnauth && !email) { return null; } return (
  • ); } function getSubscriptionSection() { const showSubsSection = shouldRenderLargeMenu && isPersonalized && subscriptions && subscriptions.length > 0; if (showSubsSection) { let displayedSubscriptions; if (subscriptionFilter) { const filter = subscriptionFilter.toLowerCase(); displayedSubscriptions = subscriptions.filter((sub) => sub.channelName.toLowerCase().includes(filter)); } else { displayedSubscriptions = lastActiveSubs && lastActiveSubs.length > 0 ? lastActiveSubs : subscriptions.slice(0, SIDEBAR_SUBS_DISPLAYED); } if (lastActiveSubs === undefined) { return null; // Don't show yet, just wait to save some renders } return (
      {subscriptions.length > SIDEBAR_SUBS_DISPLAYED && (
    • )} {displayedSubscriptions.map((subscription) => ( ))} {!!subscriptionFilter && !displayedSubscriptions.length && (
    • {__('No results')}
    • )} {!subscriptionFilter && (
    ); } return null; } function getFollowedTagsSection() { if (showTagSection) { return ( <>
      {displayedFollowedTags.map(({ name }, key) => (
    • ))} {followedTags.length > SIDEBAR_SUBS_DISPLAYED && (
    ); } return null; } React.useEffect(() => { // $FlowFixMe document.body.style.overflowY = showOverlay ? 'hidden' : ''; return () => { // $FlowFixMe document.body.style.overflowY = ''; }; }, [showOverlay]); React.useEffect(() => { if (purchaseSuccess) { setPulseLibrary(true); let timeout = setTimeout(() => { setPulseLibrary(false); doClearPurchasedUriSuccess(); }, 2500); return () => clearTimeout(timeout); } }, [setPulseLibrary, purchaseSuccess, doClearPurchasedUriSuccess]); React.useEffect(() => { function handleKeydown(e: SyntheticKeyboardEvent<*>) { if (e.keyCode === KEYCODES.ESCAPE && isAbsolute) { setSidebarOpen(false); } else if (e.keyCode === KEYCODES.BACKSLASH) { const hasActiveInput = document.querySelector('input:focus, textarea:focus'); if (!hasActiveInput) { setSidebarOpen(!sidebarOpen); } } } window.addEventListener('keydown', handleKeydown); return () => window.removeEventListener('keydown', handleKeydown); }, [sidebarOpen, setSidebarOpen, isAbsolute]); React.useEffect(() => { if (!window.Optanon) { const gdprDiv = document.getElementById('gdprSidebarLink'); if (gdprDiv) { gdprDiv.style.display = 'none'; } } }, [sidebarOpen]); React.useEffect(() => { doFetchLastActiveSubs(); }, []); const unAuthNudge = DOMAIN === 'lbry.tv' ? null : (
    }}> Sign up to earn %lbc% for you and your favorite creators.
    ); const helpLinks = (
    ); return (
    setSidebarOpen(false)} />
    ); } type SubItemProps = { subscription: Subscription, }; function SubscriptionListItem(props: SubItemProps) { const { subscription } = props; const { uri, channelName } = subscription; return (
  • ); } export default SideNavigation;