2019-09-26 18:28:08 +02:00
|
|
|
// @flow
|
2020-05-21 17:38:28 +02:00
|
|
|
import * as ICONS from 'constants/icons';
|
2019-09-26 18:28:08 +02:00
|
|
|
import React, { useEffect } from 'react';
|
2020-10-12 23:12:46 +02:00
|
|
|
import { Lbryio } from 'lbryinc';
|
2019-09-26 18:28:08 +02:00
|
|
|
import ClaimList from 'component/claimList';
|
|
|
|
import Page from 'component/page';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import YoutubeTransferStatus from 'component/youtubeTransferStatus';
|
2019-11-15 21:48:57 +01:00
|
|
|
import Spinner from 'component/spinner';
|
2020-09-04 19:14:48 +02:00
|
|
|
import Yrbl from 'component/yrbl';
|
2020-10-12 23:12:46 +02:00
|
|
|
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';
|
2022-03-16 16:34:34 +01:00
|
|
|
import ChannelSelector from 'component/channelSelector';
|
2021-06-18 18:02:36 +02:00
|
|
|
import { useHistory } from 'react-router';
|
2022-03-09 19:05:37 +01:00
|
|
|
import useGetUserMemberships from 'effects/use-get-user-memberships';
|
2019-09-26 18:28:08 +02:00
|
|
|
|
|
|
|
type Props = {
|
2020-06-21 18:51:06 +02:00
|
|
|
channelUrls: Array<string>,
|
2019-09-26 18:28:08 +02:00
|
|
|
fetchChannelListMine: () => void,
|
|
|
|
fetchingChannels: boolean,
|
|
|
|
youtubeChannels: ?Array<any>,
|
2021-06-18 18:02:36 +02:00
|
|
|
doSetActiveChannel: (string) => void,
|
2021-08-26 16:51:53 +02:00
|
|
|
pendingChannels: Array<string>,
|
2022-03-09 19:05:37 +01:00
|
|
|
claimsByUri: { [string]: any },
|
|
|
|
doFetchUserMemberships: (claimIdCsv: string) => void,
|
2019-09-26 18:28:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default function ChannelsPage(props: Props) {
|
2021-08-26 16:51:53 +02:00
|
|
|
const {
|
|
|
|
channelUrls,
|
|
|
|
fetchChannelListMine,
|
|
|
|
fetchingChannels,
|
|
|
|
youtubeChannels,
|
|
|
|
doSetActiveChannel,
|
|
|
|
pendingChannels,
|
2022-03-09 19:05:37 +01:00
|
|
|
claimsByUri,
|
|
|
|
doFetchUserMemberships,
|
2021-08-26 16:51:53 +02:00
|
|
|
} = props;
|
2020-10-12 23:12:46 +02:00
|
|
|
const [rewardData, setRewardData] = React.useState();
|
2019-09-26 18:28:08 +02:00
|
|
|
const hasYoutubeChannels = youtubeChannels && Boolean(youtubeChannels.length);
|
2021-08-26 16:51:53 +02:00
|
|
|
|
2022-03-09 19:05:37 +01:00
|
|
|
const shouldFetchUserMemberships = true;
|
|
|
|
useGetUserMemberships(shouldFetchUserMemberships, channelUrls, claimsByUri, doFetchUserMemberships);
|
|
|
|
|
2021-06-18 18:02:36 +02:00
|
|
|
const { push } = useHistory();
|
2019-09-26 18:28:08 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
fetchChannelListMine();
|
2021-08-26 16:51:53 +02:00
|
|
|
}, [fetchChannelListMine]);
|
2019-09-26 18:28:08 +02:00
|
|
|
|
2020-10-12 23:12:46 +02:00
|
|
|
useEffect(() => {
|
2021-03-03 19:50:16 +01:00
|
|
|
Lbryio.call('user_rewards', 'view_rate').then((data) => setRewardData(data));
|
2020-10-12 23:12:46 +02:00
|
|
|
}, [setRewardData]);
|
|
|
|
|
2019-09-26 18:28:08 +02:00
|
|
|
return (
|
2022-02-11 19:50:55 +01:00
|
|
|
<Page className="channelsPage-wrapper">
|
2022-05-03 15:26:46 +02:00
|
|
|
<h1 className="section__title section__title--margin-bottom">{__('Active channel')}</h1>
|
2022-05-05 13:14:16 +02:00
|
|
|
<span className="section__subtitle ">{__('Select your default active channel')}</span>
|
2022-04-26 15:28:37 +02:00
|
|
|
<ChannelSelector storeSelection />
|
2022-03-16 16:34:34 +01:00
|
|
|
|
2020-06-30 07:51:15 +02:00
|
|
|
<div className="card-stack">
|
|
|
|
{hasYoutubeChannels && <YoutubeTransferStatus hideChannelLink />}
|
|
|
|
|
2022-05-03 15:26:46 +02:00
|
|
|
<Button
|
|
|
|
button="primary"
|
|
|
|
label={__('Sync YouTube Channel')}
|
|
|
|
icon={ICONS.YOUTUBE}
|
|
|
|
navigate={`/$/${PAGES.YOUTUBE_SYNC}`}
|
|
|
|
/>
|
|
|
|
|
2020-06-30 07:51:15 +02:00
|
|
|
{channelUrls && Boolean(channelUrls.length) && (
|
2020-09-16 22:12:47 +02:00
|
|
|
<ClaimList
|
2022-03-09 19:05:37 +01:00
|
|
|
showMemberBadge
|
2020-09-16 22:12:47 +02:00
|
|
|
header={<h1 className="section__title">{__('Your channels')}</h1>}
|
|
|
|
headerAltControls={
|
|
|
|
<Button
|
|
|
|
button="secondary"
|
|
|
|
icon={ICONS.CHANNEL}
|
|
|
|
label={__('New Channel')}
|
|
|
|
navigate={`/$/${PAGES.CHANNEL_NEW}`}
|
|
|
|
/>
|
2020-06-30 07:51:15 +02:00
|
|
|
}
|
2020-09-16 22:12:47 +02:00
|
|
|
loading={fetchingChannels}
|
|
|
|
uris={channelUrls}
|
2021-03-03 19:50:16 +01:00
|
|
|
renderActions={(claim) => {
|
2020-10-12 23:12:46 +02:00
|
|
|
const claimsInChannel = claim.meta.claims_in_channel;
|
|
|
|
return claimsInChannel === 0 ? (
|
|
|
|
<span />
|
|
|
|
) : (
|
|
|
|
<div className="section__actions">
|
|
|
|
<Button
|
|
|
|
button="alt"
|
|
|
|
icon={ICONS.ANALYTICS}
|
|
|
|
label={__('Analytics')}
|
2021-06-18 18:02:36 +02:00
|
|
|
onClick={() => {
|
|
|
|
doSetActiveChannel(claim.claim_id);
|
|
|
|
push(`/$/${PAGES.CREATOR_DASHBOARD}`);
|
|
|
|
}}
|
2020-10-12 23:12:46 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}}
|
2021-03-03 19:50:16 +01:00
|
|
|
renderProperties={(claim) => {
|
2020-10-12 23:12:46 +02:00
|
|
|
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 &&
|
2021-03-03 19:50:16 +01:00
|
|
|
rewardData.rates.find((data) => {
|
2020-10-12 23:12:46 +02:00
|
|
|
return data.channel_claim_id === claim.claim_id;
|
|
|
|
});
|
|
|
|
|
2021-08-26 16:51:53 +02:00
|
|
|
if (channelRewardData && !pendingChannels.includes(claim.permanent_url)) {
|
2020-10-12 23:12:46 +02:00
|
|
|
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>
|
2020-10-12 23:12:46 +02:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}}
|
2020-06-30 07:51:15 +02:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
2019-09-26 18:28:08 +02:00
|
|
|
|
2020-06-21 18:51:06 +02:00
|
|
|
{!(channelUrls && channelUrls.length) && (
|
2019-11-15 21:48:57 +01:00
|
|
|
<React.Fragment>
|
|
|
|
{!fetchingChannels ? (
|
2022-06-10 08:45:42 +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}`} />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
2019-11-15 21:48:57 +01:00
|
|
|
) : (
|
|
|
|
<section className="main--empty">
|
2020-09-04 19:14:48 +02:00
|
|
|
<Spinner delayed />
|
2019-11-15 21:48:57 +01:00
|
|
|
</section>
|
|
|
|
)}
|
|
|
|
</React.Fragment>
|
2019-09-26 18:28:08 +02:00
|
|
|
)}
|
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
}
|