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

87 lines
2.8 KiB
React
Raw Normal View History

// @flow
2021-03-17 21:53:35 +01:00
import { ENABLE_NO_SOURCE_CLAIMS } from 'config';
import React from 'react';
import UriIndicator from 'component/uriIndicator';
import DateTime from 'component/dateTime';
import LivestreamDateTime from 'component/livestreamDateTime';
import Button from 'component/button';
import FileViewCountInline from 'component/fileViewCountInline';
import { toCompactNotation } from 'util/string';
import { parseURI } from 'util/lbryURI';
type Props = {
uri: string,
type?: string,
showAtSign?: boolean,
// --- redux ---
claim: ?StreamClaim,
pending?: boolean,
beginPublish: (?string) => void,
2021-03-17 21:53:35 +01:00
isLivestream: boolean,
lang: string,
fetchSubCount: (string) => void,
subCount: number,
};
// previews used in channel overview and homepage (and other places?)
2020-01-30 23:25:15 +01:00
function ClaimPreviewSubtitle(props: Props) {
const { pending, uri, claim, type, beginPublish, isLivestream, fetchSubCount, subCount, showAtSign, lang } = props;
const isChannel = claim && claim.value_type === 'channel';
const claimsInChannel = (claim && claim.meta.claims_in_channel) || 0;
const claimId = (claim && claim.claim_id) || '0';
const formattedSubCount = toCompactNotation(subCount, lang, 10000);
React.useEffect(() => {
if (isChannel) {
fetchSubCount(claimId);
}
}, [isChannel, fetchSubCount, claimId]);
let name;
try {
({ streamName: name } = parseURI(uri));
} catch (e) {}
return (
<div className="media__subtitle">
{claim ? (
<React.Fragment>
<UriIndicator uri={uri} showAtSign={showAtSign} link />{' '}
2021-03-17 21:53:35 +01:00
{!pending && claim && (
<>
{isChannel && type !== 'inline' && (
<>
<span className="claim-preview-metadata-sub-upload">
{subCount === 1 ? __('1 Follower') : __('%formattedSubCount% Followers', { formattedSubCount })}
&nbsp;&bull; {claimsInChannel} {claimsInChannel === 1 ? __('upload') : __('uploads')}
</span>
</>
)}
2021-03-17 21:53:35 +01:00
{!isChannel &&
(isLivestream && ENABLE_NO_SOURCE_CLAIMS ? (
<LivestreamDateTime uri={uri} />
) : (
<>
<FileViewCountInline uri={uri} isLivestream={isLivestream} />
<DateTime timeAgo uri={uri} />
</>
))}
2021-03-17 21:53:35 +01:00
</>
)}
</React.Fragment>
) : (
<React.Fragment>
2020-07-23 19:02:07 +02:00
<div>{__('Upload something and claim this spot!')}</div>
<div className="card__actions">
<Button onClick={() => beginPublish(name)} button="primary" label={__('Publish to %uri%', { uri })} />
</div>
</React.Fragment>
)}
</div>
);
}
2020-01-30 23:25:15 +01:00
export default ClaimPreviewSubtitle;