// @flow import * as ICONS from 'constants/icons'; import * as PAGES from 'constants/pages'; import * as SETTINGS from 'constants/settings'; import classnames from 'classnames'; import React from 'react'; import ChannelThumbnail from 'component/channelThumbnail'; import { Menu, MenuList, MenuButton, MenuItem } from '@reach/menu-button'; import ChannelTitle from 'component/channelTitle'; import Icon from 'component/common/icon'; import { useHistory } from 'react-router'; import useGetUserMemberships from 'effects/use-get-user-memberships'; import PremiumBadge from 'component/common/premium-badge'; type Props = { selectedChannelUrl: string, // currently selected channel channels: ?Array, onChannelSelect: (url: string) => void, hideAnon?: boolean, activeChannelClaim: ?ChannelClaim, doSetActiveChannel: (claimId: ?string, override?: boolean) => void, incognito: boolean, doSetIncognito: (boolean) => void, claimsByUri: { [string]: any }, doFetchUserMemberships: (claimIdCsv: string) => void, odyseeMembershipByUri: (uri: string) => string, storeSelection?: boolean, doSetClientSetting: (key: string, value: string, pushPrefs: boolean) => void, isHeaderMenu?: boolean, }; export default function ChannelSelector(props: Props) { const { channels, activeChannelClaim, doSetActiveChannel, incognito, doSetIncognito, odyseeMembershipByUri, claimsByUri, doFetchUserMemberships, storeSelection, doSetClientSetting, isHeaderMenu, } = props; const hideAnon = Boolean(props.hideAnon || storeSelection); const { push, location: { pathname }, } = useHistory(); const activeChannelUrl = activeChannelClaim && activeChannelClaim.permanent_url; function handleChannelSelect(channelClaim) { doSetIncognito(false); doSetActiveChannel(channelClaim.claim_id); if (storeSelection) { doSetClientSetting(SETTINGS.ACTIVE_CHANNEL_CLAIM, channelClaim.claim_id, true); } } return (
{isHeaderMenu ? ( {__('Change Default Channel')} ) : ( {(incognito && !hideAnon) || !activeChannelUrl ? ( ) : ( )} )} {channels && channels.map((channel) => ( handleChannelSelect(channel)}> ))} {!hideAnon && ( doSetIncognito(true)}> )} push(`/$/${PAGES.CHANNEL_NEW}?redirect=${pathname}`)}>

{__('Create a new channel')}

); } type ListItemProps = { uri: string, isSelected?: boolean, claimsByUri: { [string]: any }, doFetchUserMemberships: (claimIdCsv: string) => void, odyseeMembershipByUri: (uri: string) => string, }; function ChannelListItem(props: ListItemProps) { const { uri, isSelected = false, claimsByUri, doFetchUserMemberships, odyseeMembershipByUri } = props; const membership = odyseeMembershipByUri(uri); const shouldFetchUserMemberships = true; useGetUserMemberships(shouldFetchUserMemberships, [uri], claimsByUri, doFetchUserMemberships, [uri]); return (
{isSelected && }
); } type IncognitoSelectorProps = { isSelected?: boolean, }; function IncognitoSelector(props: IncognitoSelectorProps) { return (

{__('Anonymous')}

{props.isSelected && }
); }