2020-03-25 04:15:05 +01:00
|
|
|
// @flow
|
2020-10-23 21:55:19 +02:00
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import * as MODALS from 'constants/modal_types';
|
2020-09-30 22:46:20 +02:00
|
|
|
import React from 'react';
|
|
|
|
import classnames from 'classnames';
|
2020-10-23 00:11:22 +02:00
|
|
|
import { formatCredits } from 'lbry-redux';
|
2020-03-25 04:15:05 +01:00
|
|
|
import MarkdownPreview from 'component/common/markdown-preview';
|
|
|
|
import ClaimTags from 'component/claimTags';
|
2020-09-30 22:46:20 +02:00
|
|
|
import Button from 'component/button';
|
2020-10-23 00:11:22 +02:00
|
|
|
import LbcSymbol from 'component/common/lbc-symbol';
|
|
|
|
import FileDetails from 'component/fileDetails';
|
|
|
|
import FileValues from 'component/fileValues';
|
2020-03-25 04:15:05 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
|
|
|
claim: StreamClaim,
|
|
|
|
metadata: StreamMetadata,
|
|
|
|
user: ?any,
|
|
|
|
tags: any,
|
2020-10-23 00:11:22 +02:00
|
|
|
pendingAmount: number,
|
2020-10-23 21:55:19 +02:00
|
|
|
doOpenModal: (id: string, {}) => void,
|
|
|
|
claimIsMine: boolean,
|
2020-03-25 04:15:05 +01:00
|
|
|
};
|
|
|
|
|
2020-09-30 22:46:20 +02:00
|
|
|
function FileDescription(props: Props) {
|
2020-11-04 19:57:18 +01:00
|
|
|
const { uri, claim, metadata, pendingAmount, doOpenModal, claimIsMine } = props;
|
2020-09-30 22:46:20 +02:00
|
|
|
const [expanded, setExpanded] = React.useState(false);
|
2020-10-23 00:11:22 +02:00
|
|
|
const [showCreditDetails, setShowCreditDetails] = React.useState(false);
|
|
|
|
const amount = parseFloat(claim.amount) + parseFloat(pendingAmount || claim.meta.support_amount);
|
|
|
|
const formattedAmount = formatCredits(amount, 2, true);
|
2020-10-23 21:55:19 +02:00
|
|
|
const hasSupport = claim && claim.meta && claim.meta.support_amount && Number(claim.meta.support_amount) > 0;
|
2020-03-25 04:15:05 +01:00
|
|
|
|
2020-09-30 22:46:20 +02:00
|
|
|
if (!claim || !metadata) {
|
|
|
|
return <span className="empty">{__('Empty claim or metadata info.')}</span>;
|
2020-03-25 04:15:05 +01:00
|
|
|
}
|
2020-09-30 22:46:20 +02:00
|
|
|
|
|
|
|
const { description } = metadata;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div
|
2020-09-11 17:42:20 +02:00
|
|
|
className={classnames({
|
|
|
|
'media__info-text--contracted': !expanded,
|
|
|
|
'media__info-text--expanded': expanded,
|
2020-10-23 00:11:22 +02:00
|
|
|
'media__info-text--fade': !expanded,
|
2020-09-11 17:42:20 +02:00
|
|
|
})}
|
2020-09-30 22:46:20 +02:00
|
|
|
>
|
2020-11-04 19:57:18 +01:00
|
|
|
{description && <MarkdownPreview className="markdown-preview--description" content={description} simpleLinks />}
|
2020-09-30 22:46:20 +02:00
|
|
|
<ClaimTags uri={uri} type="large" />
|
2020-10-23 00:11:22 +02:00
|
|
|
<FileDetails uri={uri} />
|
2020-09-30 22:46:20 +02:00
|
|
|
</div>
|
2020-10-23 00:11:22 +02:00
|
|
|
|
2021-03-03 20:23:42 +01:00
|
|
|
<div className="card__bottom-actions">
|
2020-10-23 00:11:22 +02:00
|
|
|
{expanded ? (
|
|
|
|
<Button button="link" label={__('Less')} onClick={() => setExpanded(!expanded)} />
|
|
|
|
) : (
|
|
|
|
<Button button="link" label={__('More')} onClick={() => setExpanded(!expanded)} />
|
|
|
|
)}
|
|
|
|
|
2020-10-23 21:55:19 +02:00
|
|
|
<div className="section__actions--no-margin">
|
|
|
|
{claimIsMine && hasSupport && (
|
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
className="expandable__button"
|
|
|
|
icon={ICONS.UNLOCK}
|
2021-03-25 08:55:33 +01:00
|
|
|
aria-label={__('Unlock tips')}
|
2020-10-23 21:55:19 +02:00
|
|
|
onClick={() => {
|
|
|
|
doOpenModal(MODALS.LIQUIDATE_SUPPORTS, { uri });
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<Button button="link" onClick={() => setShowCreditDetails(!showCreditDetails)}>
|
|
|
|
<LbcSymbol postfix={showCreditDetails ? __('Hide') : formattedAmount} />
|
|
|
|
</Button>
|
|
|
|
</div>
|
2020-10-23 00:11:22 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
{showCreditDetails && (
|
|
|
|
<div className="section">
|
|
|
|
<FileValues uri={uri} />
|
2020-09-30 22:46:20 +02:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
2020-03-25 04:15:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default FileDescription;
|