2019-09-26 18:28:08 +02:00
|
|
|
// @flow
|
|
|
|
import * as React from 'react';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import ClaimPreview from 'component/claimPreview';
|
|
|
|
import Card from 'component/common/card';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
youtubeChannels: Array<any>,
|
|
|
|
ytImportPending: boolean,
|
|
|
|
claimChannels: () => void,
|
|
|
|
updateUser: () => void,
|
|
|
|
checkYoutubeTransfer: () => void,
|
|
|
|
videosImported: ?Array<number>, // [currentAmountImported, totalAmountToImport]
|
|
|
|
};
|
|
|
|
|
2019-09-27 20:56:15 +02:00
|
|
|
const NOT_TRANSFERRED = 'not_transferred';
|
2019-09-26 18:28:08 +02:00
|
|
|
const PENDING_TRANSFER = 'pending_transfer';
|
|
|
|
const COMPLETED_TRANSFER = 'completed_transfer';
|
|
|
|
|
|
|
|
export default function YoutubeTransferStatus(props: Props) {
|
|
|
|
const { youtubeChannels, ytImportPending, claimChannels, videosImported, checkYoutubeTransfer, updateUser } = props;
|
|
|
|
const hasChannels = youtubeChannels && youtubeChannels.length;
|
|
|
|
|
2019-09-30 21:52:53 +02:00
|
|
|
const transferEnabled = youtubeChannels.some(status => status.transferable);
|
|
|
|
const hasPendingTransfers = youtubeChannels.some(status => status.transfer_state === PENDING_TRANSFER);
|
|
|
|
const hasCompleteTransfers = youtubeChannels.some(status => status.transfer_state === COMPLETED_TRANSFER);
|
|
|
|
console.log('?', hasChannels && (hasPendingTransfers || (!hasPendingTransfers && !hasCompleteTransfers)));
|
2019-09-26 18:28:08 +02:00
|
|
|
|
|
|
|
let total;
|
|
|
|
let complete;
|
2019-09-30 21:52:53 +02:00
|
|
|
if (hasPendingTransfers && videosImported) {
|
2019-09-26 18:28:08 +02:00
|
|
|
complete = videosImported[0];
|
|
|
|
total = videosImported[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
function getMessage(channel) {
|
|
|
|
const { transferable, transfer_state: transferState, sync_status: syncStatus } = channel;
|
|
|
|
if (!transferable) {
|
|
|
|
switch (transferState) {
|
2019-09-27 20:56:15 +02:00
|
|
|
case NOT_TRANSFERRED:
|
2019-09-26 18:28:08 +02:00
|
|
|
return syncStatus[0].toUpperCase() + syncStatus.slice(1);
|
|
|
|
case PENDING_TRANSFER:
|
|
|
|
return __('Transfer in progress');
|
|
|
|
case COMPLETED_TRANSFER:
|
|
|
|
return __('Completed transfer');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return __('Ready to transfer');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
// If a channel is transferrable, theres nothing to check
|
2019-09-30 21:52:53 +02:00
|
|
|
if (hasPendingTransfers) {
|
2019-09-26 18:28:08 +02:00
|
|
|
checkYoutubeTransfer();
|
|
|
|
|
|
|
|
let interval = setInterval(() => {
|
|
|
|
checkYoutubeTransfer();
|
|
|
|
updateUser();
|
|
|
|
}, 60 * 1000);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
clearInterval(interval);
|
|
|
|
};
|
|
|
|
}
|
2019-09-30 21:52:53 +02:00
|
|
|
}, [hasPendingTransfers, checkYoutubeTransfer, updateUser]);
|
2019-09-26 18:28:08 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
hasChannels &&
|
2019-09-30 21:52:53 +02:00
|
|
|
(hasPendingTransfers || transferEnabled) && (
|
2019-09-26 18:28:08 +02:00
|
|
|
<div>
|
|
|
|
<Card
|
2019-09-27 20:56:15 +02:00
|
|
|
title={youtubeChannels.length > 1 ? __('Your YouTube Channels') : __('Your YouTube Channel')}
|
2019-09-26 18:28:08 +02:00
|
|
|
subtitle={
|
|
|
|
<span>
|
2019-09-30 21:52:53 +02:00
|
|
|
{hasPendingTransfers
|
2019-09-27 20:56:15 +02:00
|
|
|
? __('Your videos are currently being transferred. There is nothing else for you to do.')
|
|
|
|
: __('Your videos are ready to be transferred.')}
|
2019-09-26 18:28:08 +02:00
|
|
|
</span>
|
|
|
|
}
|
|
|
|
body={
|
|
|
|
<section>
|
2019-09-27 20:56:15 +02:00
|
|
|
{youtubeChannels.map((channel, index) => {
|
|
|
|
const { lbry_channel_name: channelName, channel_claim_id: claimId } = channel;
|
|
|
|
const url = `lbry://${channelName}#${claimId}`;
|
2019-09-26 18:28:08 +02:00
|
|
|
const transferState = getMessage(channel);
|
|
|
|
return (
|
2019-09-27 20:56:15 +02:00
|
|
|
<div key={url} className="card--inline">
|
2019-09-26 18:28:08 +02:00
|
|
|
<ClaimPreview uri={url} actions={<span className="help">{transferState}</span>} properties={''} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
{videosImported && (
|
|
|
|
<div className="section help">
|
|
|
|
{complete} / {total} {__('videos transferred')}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</section>
|
|
|
|
}
|
|
|
|
actions={
|
2019-09-30 21:52:53 +02:00
|
|
|
transferEnabled && (
|
2019-09-26 18:28:08 +02:00
|
|
|
<div className="card__actions">
|
2019-09-30 21:52:53 +02:00
|
|
|
<Button
|
|
|
|
button="primary"
|
|
|
|
disabled={ytImportPending}
|
|
|
|
onClick={claimChannels}
|
|
|
|
label={youtubeChannels.length > 1 ? __('Claim Channels') : __('Claim Channel')}
|
|
|
|
/>
|
2019-09-26 18:28:08 +02:00
|
|
|
<Button button="link" label={__('Learn more')} href="https://lbry.com/faq/youtube#transfer" />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|