lbry-desktop/ui/page/channels/view.jsx

157 lines
5.2 KiB
React
Raw Normal View History

// @flow
2020-05-21 17:38:28 +02:00
import * as ICONS from 'constants/icons';
import React, { useEffect } from 'react';
import { Lbryio } from 'lbryinc';
import ClaimList from 'component/claimList';
import Page from 'component/page';
import Button from 'component/button';
import YoutubeTransferStatus from 'component/youtubeTransferStatus';
import Spinner from 'component/spinner';
2020-09-04 19:14:48 +02:00
import Yrbl from 'component/yrbl';
import LbcSymbol from 'component/common/lbc-symbol';
2020-06-29 21:54:07 +02:00
import * as PAGES from 'constants/pages';
2020-10-12 23:24:32 +02:00
import HelpLink from 'component/common/help-link';
import ChannelSelector from 'component/channelSelector';
import { useHistory } from 'react-router';
import useGetUserMemberships from 'effects/use-get-user-memberships';
type Props = {
2020-06-21 18:51:06 +02:00
channelUrls: Array<string>,
fetchChannelListMine: () => void,
fetchingChannels: boolean,
youtubeChannels: ?Array<any>,
doSetActiveChannel: (string) => void,
pendingChannels: Array<string>,
claimsByUri: { [string]: any },
doFetchUserMemberships: (claimIdCsv: string) => void,
};
export default function ChannelsPage(props: Props) {
const {
channelUrls,
fetchChannelListMine,
fetchingChannels,
youtubeChannels,
doSetActiveChannel,
pendingChannels,
claimsByUri,
doFetchUserMemberships,
} = props;
const [rewardData, setRewardData] = React.useState();
const hasYoutubeChannels = youtubeChannels && Boolean(youtubeChannels.length);
const shouldFetchUserMemberships = true;
useGetUserMemberships(shouldFetchUserMemberships, channelUrls, claimsByUri, doFetchUserMemberships);
const { push } = useHistory();
useEffect(() => {
fetchChannelListMine();
}, [fetchChannelListMine]);
useEffect(() => {
Lbryio.call('user_rewards', 'view_rate').then((data) => setRewardData(data));
}, [setRewardData]);
return (
<Page className="channelsPage-wrapper">
{/* TODO: use variabled spacing */}
<h1 className="section__title" style={{ marginBottom: '15px' }}>
2022-03-22 20:08:56 +01:00
{__('Active channel')}
</h1>
<ChannelSelector />
<div className="card-stack">
{hasYoutubeChannels && <YoutubeTransferStatus hideChannelLink />}
{channelUrls && Boolean(channelUrls.length) && (
<ClaimList
showMemberBadge
header={<h1 className="section__title">{__('Your channels')}</h1>}
headerAltControls={
<Button
button="secondary"
icon={ICONS.CHANNEL}
label={__('New Channel')}
navigate={`/$/${PAGES.CHANNEL_NEW}`}
/>
}
loading={fetchingChannels}
uris={channelUrls}
renderActions={(claim) => {
const claimsInChannel = claim.meta.claims_in_channel;
return claimsInChannel === 0 ? (
<span />
) : (
<div className="section__actions">
<Button
button="alt"
icon={ICONS.ANALYTICS}
label={__('Analytics')}
onClick={() => {
doSetActiveChannel(claim.claim_id);
push(`/$/${PAGES.CREATOR_DASHBOARD}`);
}}
/>
</div>
);
}}
renderProperties={(claim) => {
const claimsInChannel = claim.meta.claims_in_channel;
if (!claim || claimsInChannel === 0) {
return null;
}
const channelRewardData =
rewardData &&
2020-10-16 04:29:19 +02:00
rewardData.rates &&
rewardData.rates.find((data) => {
return data.channel_claim_id === claim.claim_id;
});
if (channelRewardData && !pendingChannels.includes(claim.permanent_url)) {
return (
<span className="claim-preview__custom-properties">
2020-10-12 23:24:32 +02:00
<span className="help--inline">
2021-10-21 22:21:51 +02:00
{__('Earnings per view')}{' '}
<HelpLink href="https://odysee.com/@OdyseeHelp:b/Monetization-of-Content:3" />
2020-10-12 23:24:32 +02:00
</span>
2020-12-21 20:25:41 +01:00
<span>
<LbcSymbol postfix={channelRewardData.view_rate.toFixed(2)} />
</span>
</span>
);
} else {
return null;
}
}}
/>
)}
</div>
2020-06-21 18:51:06 +02:00
{!(channelUrls && channelUrls.length) && (
<React.Fragment>
{!fetchingChannels ? (
<section className="main--empty">
2020-09-04 19:14:48 +02:00
<Yrbl
title={__('No channels')}
subtitle={__("You haven't created a channel yet. All of your beautiful channels will be listed here!")}
actions={
<div className="section__actions">
<Button button="primary" label={__('Create Channel')} navigate={`/$/${PAGES.CHANNEL_NEW}`} />
2020-09-04 19:14:48 +02:00
</div>
}
/>
</section>
) : (
<section className="main--empty">
2020-09-04 19:14:48 +02:00
<Spinner delayed />
</section>
)}
</React.Fragment>
)}
</Page>
);
}