2020-03-18 18:11:37 +01:00
|
|
|
// @flow
|
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import React from 'react';
|
|
|
|
import ChannelThumbnail from 'component/channelThumbnail';
|
|
|
|
import { Menu, MenuList, MenuButton, MenuItem } from '@reach/menu-button';
|
2020-03-18 22:14:11 +01:00
|
|
|
import ChannelTitle from 'component/channelTitle';
|
2020-03-18 18:11:37 +01:00
|
|
|
import Icon from 'component/common/icon';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
selectedChannelUrl: string, // currently selected channel
|
|
|
|
channels: ?Array<ChannelClaim>,
|
|
|
|
onChannelSelect: (url: string) => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
type ListItemProps = {
|
2020-03-18 22:14:11 +01:00
|
|
|
uri: string,
|
2020-03-18 18:11:37 +01:00
|
|
|
isSelected?: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
function ChannelListItem(props: ListItemProps) {
|
2020-03-18 22:14:11 +01:00
|
|
|
const { uri, isSelected = false } = props;
|
2020-03-18 18:11:37 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={classnames('channel__list-item', { 'channel__list-item--selected': isSelected })}>
|
2020-03-18 22:14:11 +01:00
|
|
|
<ChannelThumbnail uri={uri} />
|
|
|
|
<ChannelTitle uri={uri} />
|
2020-03-18 18:11:37 +01:00
|
|
|
{isSelected && <Icon icon={ICONS.DOWN} />}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ChannelSelector(props: Props) {
|
|
|
|
const { channels, selectedChannelUrl, onChannelSelect } = props;
|
|
|
|
|
2020-03-18 22:14:11 +01:00
|
|
|
if (!channels || !selectedChannelUrl) {
|
2020-03-18 18:11:37 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Menu>
|
|
|
|
<MenuButton className="">
|
2020-03-18 22:14:11 +01:00
|
|
|
<ChannelListItem uri={selectedChannelUrl} isSelected />
|
2020-03-18 18:11:37 +01:00
|
|
|
</MenuButton>
|
2020-03-18 18:33:17 +01:00
|
|
|
<MenuList className="menu__list">
|
2020-03-18 18:11:37 +01:00
|
|
|
{channels &&
|
|
|
|
channels.map(channel => (
|
2020-03-20 20:16:47 +01:00
|
|
|
<MenuItem
|
|
|
|
key={channel.canonical_url}
|
|
|
|
onSelect={() => {
|
|
|
|
if (selectedChannelUrl !== channel.canonical_url) {
|
|
|
|
onChannelSelect(channel.canonical_url);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2020-03-18 22:14:11 +01:00
|
|
|
<ChannelListItem uri={channel.canonical_url} />
|
2020-03-18 18:11:37 +01:00
|
|
|
</MenuItem>
|
|
|
|
))}
|
|
|
|
</MenuList>
|
|
|
|
</Menu>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ChannelSelector;
|