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

88 lines
2.7 KiB
React
Raw Normal View History

// @flow
2020-05-21 17:38:28 +02:00
import * as MODALS from 'constants/modal_types';
import * as ICONS from 'constants/icons';
import React, { useEffect } from 'react';
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-05-21 17:38:28 +02:00
import Card from 'component/common/card';
type Props = {
channels: Array<ChannelClaim>,
fetchChannelListMine: () => void,
fetchingChannels: boolean,
youtubeChannels: ?Array<any>,
2019-12-06 20:42:44 +01:00
openModal: string => void,
};
export default function ChannelsPage(props: Props) {
2020-06-19 19:10:34 +02:00
const { channels, fetchChannelListMine, fetchingChannels, youtubeChannels, openModal } = props;
const hasYoutubeChannels = youtubeChannels && Boolean(youtubeChannels.length);
2019-12-09 16:16:49 +01:00
const hasPendingChannels = channels && channels.some(channel => channel.confirmations < 0);
useEffect(() => {
fetchChannelListMine();
2020-06-19 19:10:34 +02:00
let interval;
if (hasPendingChannels) {
interval = setInterval(() => {
fetchChannelListMine();
}, 5000);
}
return () => {
clearInterval(interval);
};
2019-10-03 23:40:54 +02:00
}, [fetchChannelListMine, hasPendingChannels]);
return (
<Page>
2019-10-03 23:40:54 +02:00
{hasYoutubeChannels && <YoutubeTransferStatus hideChannelLink />}
2020-06-19 19:10:34 +02:00
{channels && Boolean(channels.length) && (
2020-05-21 17:38:28 +02:00
<Card
title={__('Your Channels')}
titleActions={
<Button
button="secondary"
icon={ICONS.CHANNEL}
label={__('New Channel')}
onClick={() => openModal(MODALS.CREATE_CHANNEL)}
/>
}
isBodyList
2020-06-19 19:10:34 +02:00
body={
<ClaimList isCardBody loading={fetchingChannels} uris={channels.map(channel => channel.permanent_url)} />
}
2020-01-03 01:06:45 +01:00
/>
)}
2020-06-19 19:10:34 +02:00
{!(channels && channels.length) && (
<React.Fragment>
{!fetchingChannels ? (
<section className="main--empty">
<div className=" section--small">
<h2 className="section__title--large">{__('No Channels Created Yet')}</h2>
<div className="section__actions">
2019-12-06 20:42:44 +01:00
<Button button="primary" label={__('New Channel')} onClick={() => openModal(MODALS.CREATE_CHANNEL)} />
</div>
</div>
</section>
) : (
<section className="main--empty">
<div className=" section--small">
<h2 className="section__title--small">
{__('Checking for channels')}
<Spinner type="small" />
</h2>
</div>
</section>
)}
</React.Fragment>
)}
</Page>
);
}