// @flow import * as ICONS from 'constants/icons'; import * as PAGES from 'constants/pages'; 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'; type Props = { selectedChannelUrl: string, // currently selected channel channels: ?Array, onChannelSelect: (url: string) => void, hideAnon?: boolean, activeChannelClaim: ?ChannelClaim, doSetActiveChannel: (string) => void, incognito: boolean, doSetIncognito: (boolean) => void, }; type ListItemProps = { uri: string, isSelected?: boolean, }; function ChannelListItem(props: ListItemProps) { const { uri, isSelected = false } = props; return (
{isSelected && }
); } type IncognitoSelectorProps = { isSelected?: boolean, }; function IncognitoSelector(props: IncognitoSelectorProps) { return (

{__('Anonymous')}

{props.isSelected && }
); } function ChannelSelector(props: Props) { const { channels, activeChannelClaim, doSetActiveChannel, hideAnon = false, incognito, doSetIncognito } = props; const { push, location: { pathname }, } = useHistory(); const activeChannelUrl = activeChannelClaim && activeChannelClaim.permanent_url; function handleChannelSelect(channelClaim) { doSetIncognito(false); doSetActiveChannel(channelClaim.claim_id); } return (
{(incognito && !hideAnon) || !activeChannelUrl ? ( ) : ( )} {channels && channels.map((channel) => ( handleChannelSelect(channel)}> ))} {!hideAnon && ( doSetIncognito(true)}> )} push(`/$/${PAGES.CHANNEL_NEW}?redirect=${pathname}`)}>

{__('Create a new channel')}

); } export default ChannelSelector;