// @flow import type { Node } from 'react'; import * as PAGES from 'constants/pages'; import * as ICONS from 'constants/icons'; import React 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 { PINNED_LABEL_1, PINNED_URI_1, PINNED_URI_2, PINNED_LABEL_2, SIMPLE_SITE } from 'config'; // @if TARGET='app' import { IS_MAC } from 'component/app/view'; // @endif const ESCAPE_KEY_CODE = 27; const BACKSLASH_KEY_CODE = 220; const HOME = { title: 'Home', link: `/`, icon: ICONS.HOME, }; const RECENT_FROM_FOLLOWING = { title: 'Following --[sidebar button]--', link: `/$/${PAGES.CHANNELS_FOLLOWING}`, icon: ICONS.SUBSCRIBE, }; type Props = { subscriptions: Array, followedTags: Array, email: ?string, uploadCount: number, doSignOut: () => void, sidebarOpen: boolean, setSidebarOpen: boolean => void, isMediumScreen: boolean, isOnFilePage: boolean, unreadCount: number, purchaseSuccess: boolean, doClearPurchasedUriSuccess: () => void, user: ?User, homepageData: any, }; type SideNavLink = { title: string, link?: string, onClick?: () => any, icon: string, extra?: Node, hideForUnauth?: boolean, }; function SideNavigation(props: Props) { const { subscriptions, followedTags, doSignOut, email, purchaseSuccess, doClearPurchasedUriSuccess, sidebarOpen, setSidebarOpen, isMediumScreen, isOnFilePage, unreadCount, homepageData, user, } = props; const { EXTRA_SIDEBAR_LINKS } = homepageData; const FULL_LINKS: Array = [ { title: 'Your Tags', navigate: `/$/${PAGES.TAGS_FOLLOWING}`, icon: ICONS.TAG, hideForUnauth: true, }, { title: 'Discover', navigate: `/$/${PAGES.DISCOVER}`, icon: ICONS.DISCOVER, }, { title: IS_WEB ? 'Purchased' : 'Library', navigate: `/$/${PAGES.LIBRARY}`, icon: ICONS.PURCHASED, hideForUnauth: true, }, ]; const MOBILE_LINKS: Array = [ { title: 'Notifications', link: `/$/${PAGES.NOTIFICATIONS}`, icon: ICONS.NOTIFICATION, extra: , hideForUnauth: true, }, { title: 'Discover', link: `/$/${PAGES.DISCOVER}`, icon: ICONS.DISCOVER, }, { title: IS_WEB ? 'Purchased' : 'Library', navigate: `/$/${PAGES.LIBRARY}`, icon: ICONS.PURCHASED, hideForUnauth: true, }, { 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, }, { label: 'Rewards', navigate: `/$/${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 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, }, ]; if (PINNED_URI_1 && PINNED_LABEL_1) { MOBILE_LINKS.push({ label: PINNED_LABEL_1, navigate: PINNED_URI_1, icon: ICONS.PINNED, }); } if (PINNED_URI_2 && PINNED_LABEL_2) { MOBILE_LINKS.push({ label: PINNED_LABEL_2, navigate: PINNED_URI_2, icon: ICONS.PINNED, }); } const notificationsEnabled = user && user.experimental_ui; const isAuthenticated = Boolean(email); // SIDE LINKS: FOLLOWING, HOME, [FULL,] [EXTRA] let SIDE_LINKS: Array = []; if (isAuthenticated) { SIDE_LINKS.push(RECENT_FROM_FOLLOWING); } SIDE_LINKS.push(HOME); if (!SIMPLE_SITE) { SIDE_LINKS.push(...FULL_LINKS); } // $FlowFixMe if (EXTRA_SIDEBAR_LINKS) { SIDE_LINKS.push(EXTRA_SIDEBAR_LINKS); } const [pulseLibrary, setPulseLibrary] = React.useState(false); const isPersonalized = !IS_WEB || isAuthenticated; const isAbsolute = isOnFilePage || isMediumScreen; const microNavigation = !sidebarOpen || isMediumScreen; const subLinks = email ? MOBILE_LINKS.filter(link => { if (!notificationsEnabled && link.icon === ICONS.NOTIFICATION) { return false; } return true; }) : UNAUTH_LINKS; 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 === ESCAPE_KEY_CODE && isAbsolute) { setSidebarOpen(false); } else if (e.keyCode === BACKSLASH_KEY_CODE) { const hasActiveInput = document.querySelector('input:focus'); if (!hasActiveInput) { setSidebarOpen(!sidebarOpen); } } } window.addEventListener('keydown', handleKeydown); return () => window.removeEventListener('keydown', handleKeydown); }, [sidebarOpen, setSidebarOpen, isAbsolute]); const unAuthNudge = (
}}> Sign up to earn %lbc% for you and your favorite creators.
); return (
{!isOnFilePage && ( )} {(isOnFilePage || isMediumScreen) && sidebarOpen && ( <>
setSidebarOpen(false)} /> )}
); } export default SideNavigation;