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

87 lines
2.8 KiB
React
Raw Normal View History

// @flow
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';
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';
type Props = {
uri: string,
claim: StreamClaim,
metadata: StreamMetadata,
user: ?any,
tags: any,
2020-10-23 00:11:22 +02:00
pendingAmount: number,
doOpenModal: (id: string, {}) => void,
claimIsMine: boolean,
};
2020-09-30 22:46:20 +02:00
function FileDescription(props: Props) {
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);
const hasSupport = claim && claim.meta && claim.meta.support_amount && Number(claim.meta.support_amount) > 0;
2020-09-30 22:46:20 +02:00
if (!claim || !metadata) {
return <span className="empty">{__('Empty claim or metadata info.')}</span>;
}
2020-09-30 22:46:20 +02:00
const { description } = metadata;
return (
<div>
<div
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-30 22:46:20 +02: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
<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)} />
)}
<div className="section__actions--no-margin">
{claimIsMine && hasSupport && (
<Button
button="link"
className="expandable__button"
icon={ICONS.UNLOCK}
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>
);
}
export default FileDescription;