lbry-desktop/ui/component/channelSelector/view.jsx

65 lines
1.7 KiB
React
Raw Normal View History

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 (
2020-05-08 03:53:00 +02:00
<Menu>
<MenuButton className="">
<ChannelListItem uri={selectedChannelUrl} isSelected />
</MenuButton>
<MenuList className="menu__list channel__list">
{channels &&
channels.map(channel => (
<MenuItem
key={channel.canonical_url}
onSelect={() => {
if (selectedChannelUrl !== channel.canonical_url) {
onChannelSelect(channel.canonical_url);
}
}}
>
<ChannelListItem uri={channel.canonical_url} />
</MenuItem>
))}
</MenuList>
</Menu>
2020-03-18 18:11:37 +01:00
);
}
export default ChannelSelector;