// @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, ENABLE_NO_SOURCE_CLAIMS } from 'config'; import PremiumBadge from 'component/common/premium-badge'; const touch = platform.isTouch(); type SideNavLink = { title: string, icon: string, link?: string, route?: string, onClick?: () => any, extra?: Node, hideForUnauth?: boolean, noI18n?: boolean, }; const GO_LIVE: SideNavLink = { title: 'Go Live', link: `/$/${PAGES.LIVESTREAM}`, icon: ICONS.VIDEO, }; 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, odyseeMembershipByUri: (uri: string) => 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, odyseeMembershipByUri, doFetchLastActiveSubs, } = props; const isLargeScreen = useIsLargeScreen(); const EXTRA_SIDEBAR_LINKS = GetLinksData(homepageData, isLargeScreen).map( ({ pinnedUrls, pinnedClaimIds, ...theRest }) => theRest ); const MOBILE_LINKS: Array = [ { title: 'Upload', link: `/$/${PAGES.UPLOAD}`, icon: ICONS.PUBLISH, }, { 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 livestreamEnabled = Boolean(ENABLE_NO_SOURCE_CLAIMS && user && !user.odysee_live_disabled); 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, odyseeMembershipByUri: (uri: string) => string, }; function SubscriptionListItem(props: SubItemProps) { const { subscription, odyseeMembershipByUri } = props; const { uri, channelName } = subscription; const membership = odyseeMembershipByUri(uri); return (
  • ); } export default SideNavigation;