// @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 React, { useEffect } from 'react'; import Button from 'component/button'; import classnames from 'classnames'; import Icon from 'component/common/icon'; import NotificationBubble from 'component/notificationBubble'; import I18nMessage from 'component/i18nMessage'; import ChannelThumbnail from 'component/channelThumbnail'; import useDebounce from 'effects/use-debounce'; import { useIsMobile, useIsLargeScreen } from 'effects/use-screensize'; import { GetLinksData } from 'util/buildHomepage'; import { DOMAIN, ENABLE_UI_NOTIFICATIONS, ENABLE_NO_SOURCE_CLAIMS, CHANNEL_STAKED_LEVEL_LIVESTREAM } from 'config'; const FOLLOWED_ITEM_INITIAL_LIMIT = 10; const FILTER_DEBOUNCE_MS = 300; type SideNavLink = { title: string, link?: string, route?: string, onClick?: () => any, icon: string, extra?: Node, hideForUnauth?: boolean, }; const GO_LIVE = { title: 'Go Live', link: `/$/${PAGES.LIVESTREAM}`, icon: ICONS.VIDEO, }; const HOME = { title: 'Home', link: `/`, icon: ICONS.HOME, onClick: () => { if (window.location.pathname === '/') window.location.reload(); }, }; const RECENT_FROM_FOLLOWING = { title: 'Following --[sidebar button]--', link: `/$/${PAGES.CHANNELS_FOLLOWING}`, icon: ICONS.SUBSCRIBE, }; const NOTIFICATIONS = { title: 'Notifications', link: `/$/${PAGES.NOTIFICATIONS}`, icon: ICONS.NOTIFICATION, extra: , hideForUnauth: true, }; const PLAYLISTS = { title: 'Lists', link: `/$/${PAGES.LISTS}`, icon: ICONS.STACK, hideForUnauth: 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, }, ]; const WILD_WEST = { title: 'Wild West', link: `/$/${PAGES.WILD_WEST}`, icon: ICONS.WILD_WEST, }; // **************************************************************************** // **************************************************************************** type Props = { subscriptions: 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, activeChannelStakedLevel: number, }; function SideNavigation(props: Props) { const { subscriptions, doSignOut, email, purchaseSuccess, doClearPurchasedUriSuccess, sidebarOpen, setSidebarOpen, isMediumScreen, isOnFilePage, unseenCount, homepageData, user, followedTags, activeChannelStakedLevel, } = props; const isLargeScreen = useIsLargeScreen(); const EXTRA_SIDEBAR_LINKS = GetLinksData(homepageData, isLargeScreen).map(({ pinnedUrls, ...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: '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 && (activeChannelStakedLevel >= CHANNEL_STAKED_LEVEL_LIVESTREAM || user.odysee_live_enabled) ); const [pulseLibrary, setPulseLibrary] = React.useState(false); const [expandSubscriptions, setExpandSubscriptions] = 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 || sidebarOpen; const showMicroMenu = !sidebarOpen && !menuCanCloseCompletely; const showPushMenu = sidebarOpen && !menuCanCloseCompletely; const showSubscriptionSection = shouldRenderLargeMenu && isPersonalized && subscriptions && subscriptions.length > 0; const showTagSection = sidebarOpen && isPersonalized && followedTags && followedTags.length; const [rawSubscriptionFilter, setRawSubscriptionFilter] = React.useState(''); const subscriptionFilter: string = useDebounce(rawSubscriptionFilter, FILTER_DEBOUNCE_MS); const filteredSubscriptions = subscriptions.filter( (sub) => !subscriptionFilter || sub.channelName.toLowerCase().includes(subscriptionFilter) ); let displayedSubscriptions = filteredSubscriptions; if ( showSubscriptionSection && !subscriptionFilter && subscriptions.length > FOLLOWED_ITEM_INITIAL_LIMIT && !expandSubscriptions ) { displayedSubscriptions = subscriptions.slice(0, FOLLOWED_ITEM_INITIAL_LIMIT); } let displayedFollowedTags = followedTags; if (showTagSection && followedTags.length > FOLLOWED_ITEM_INITIAL_LIMIT && !expandTags) { displayedFollowedTags = followedTags.slice(0, FOLLOWED_ITEM_INITIAL_LIMIT); } function getLink(props: SideNavLink) { const { hideForUnauth, route, link, ...passedProps } = props; const { title, icon, extra } = passedProps; if (hideForUnauth && !email) { return null; } return (
  • ); } function getSubscriptionSection() { if (showSubscriptionSection) { return ( <>
    • setRawSubscriptionFilter(e.target.value.trim())} />
    • {displayedSubscriptions.map((subscription) => ( ))} {!!subscriptionFilter && !displayedSubscriptions.length && (
    • {__('No results')}
    • )} {!subscriptionFilter && subscriptions.length > FOLLOWED_ITEM_INITIAL_LIMIT && (
    ); } return null; } function getFollowedTagsSection() { if (showTagSection) { return ( <>
      {displayedFollowedTags.map(({ name }, key) => (
    • ))} {followedTags.length > FOLLOWED_ITEM_INITIAL_LIMIT && (
    ); } return null; } 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]); useEffect(() => { if (!window.Optanon) { const gdprDiv = document.getElementById('gdprSidebarLink'); if (gdprDiv) { gdprDiv.style.display = 'none'; } } }, [sidebarOpen]); const unAuthNudge = DOMAIN === 'lbry.tv' ? null : (
    }}> Sign up to earn %lbc% for you and your favorite creators.
    ); const helpLinks = (
    ); return (
    setSidebarOpen(false)} />
    ); } function SubscriptionListItem({ subscription }: { subscription: Subscription }) { const { uri, channelName } = subscription; return (
  • ); } export default SideNavigation;