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

74 lines
1.8 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import React from 'react';
2019-02-13 17:27:20 +01:00
import { FormField } from 'component/common/form';
2018-03-26 23:32:43 +02:00
type Props = {
tiny?: boolean,
label?: string,
injected?: ?Array<string>,
channelIds?: Array<string>, // Specific channel IDs to show. Must be a subset of own channels.
// --- Redux ---
myChannelClaims: ?Array<ChannelClaim>,
fetchingChannels: boolean,
activeChannelId: ?string,
setActiveChannel: (string) => void,
2018-03-26 23:32:43 +02:00
};
function SelectChannel(props: Props) {
const {
fetchingChannels,
channelIds,
myChannelClaims = [],
label,
injected = [],
tiny,
activeChannelId,
setActiveChannel,
} = props;
function handleChannelChange(event: SyntheticInputEvent<*>) {
const channelClaimId = event.target.value;
setActiveChannel(channelClaimId);
}
let mine = myChannelClaims;
if (myChannelClaims && channelIds) {
mine = myChannelClaims.filter((x) => channelIds.includes(x.claim_id));
}
return (
<>
<FormField
name="channel"
label={!tiny && (label || __('Channel'))}
labelOnLeft={tiny}
type={tiny ? 'select-tiny' : 'select'}
onChange={handleChannelChange}
value={activeChannelId}
disabled={fetchingChannels}
>
{fetchingChannels ? (
<option>{__('Loading your channels...')}</option>
) : (
<>
{mine &&
mine.map(({ name, claim_id: claimId }) => (
<option key={claimId} value={claimId}>
{name}
</option>
))}
{injected &&
injected.map((item) => (
<option key={item} value={item}>
{item}
</option>
))}
</>
)}
</FormField>
</>
);
2018-03-26 23:32:43 +02:00
}
export default SelectChannel;