2021-03-11 18:08:11 +01:00
|
|
|
// @flow
|
|
|
|
import * as React from 'react';
|
2021-05-12 20:26:47 +02:00
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import * as MODALS from 'constants/modal_types';
|
|
|
|
import { formatCredits } from 'lbry-redux';
|
2021-03-11 18:08:11 +01:00
|
|
|
import FileAuthor from 'component/fileAuthor';
|
2021-05-12 20:26:47 +02:00
|
|
|
import FileDetails from 'component/fileDetails';
|
2021-03-11 18:08:11 +01:00
|
|
|
import FileTitle from 'component/fileTitle';
|
|
|
|
import FileActions from 'component/fileActions';
|
|
|
|
import FileRenderInitiator from 'component/fileRenderInitiator';
|
|
|
|
import FileRenderInline from 'component/fileRenderInline';
|
2021-05-12 20:26:47 +02:00
|
|
|
import FileValues from 'component/fileValues';
|
2021-03-11 18:08:11 +01:00
|
|
|
import FileViewCount from 'component/fileViewCount';
|
2021-05-12 20:26:47 +02:00
|
|
|
import ClaimTags from 'component/claimTags';
|
2021-03-11 18:08:11 +01:00
|
|
|
import DateTime from 'component/dateTime';
|
2021-05-12 20:26:47 +02:00
|
|
|
import Button from 'component/button';
|
|
|
|
import LbcSymbol from 'component/common/lbc-symbol';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
|
|
|
const EXPAND = {
|
|
|
|
NONE: 'none',
|
|
|
|
CREDIT_DETAILS: 'credit_details',
|
|
|
|
FILE_DETAILS: 'file_details',
|
|
|
|
};
|
2021-03-11 18:08:11 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
|
|
|
claim: ?StreamClaim,
|
2021-05-12 20:26:47 +02:00
|
|
|
claimIsMine: boolean,
|
|
|
|
doOpenModal: (id: string, {}) => void,
|
2021-03-11 18:08:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function PostViewer(props: Props) {
|
2021-05-12 20:26:47 +02:00
|
|
|
const { uri, claim, claimIsMine, doOpenModal } = props;
|
|
|
|
const [expand, setExpand] = React.useState(EXPAND.NONE);
|
2021-03-11 18:08:11 +01:00
|
|
|
|
|
|
|
if (!claim) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const amount = parseFloat(claim.amount) + parseFloat(claim.meta.support_amount);
|
2021-05-12 20:26:47 +02:00
|
|
|
const formattedAmount = formatCredits(amount, 2, true);
|
|
|
|
const hasSupport = claim && claim.meta && claim.meta.support_amount && Number(claim.meta.support_amount) > 0;
|
|
|
|
|
|
|
|
function handleExpand(newExpand) {
|
|
|
|
if (expand === newExpand) {
|
|
|
|
setExpand(EXPAND.NONE);
|
|
|
|
} else {
|
|
|
|
setExpand(newExpand);
|
|
|
|
}
|
|
|
|
}
|
2021-03-11 18:08:11 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="post">
|
|
|
|
<FileTitle uri={uri} className="post__title">
|
|
|
|
<span className="post__date">
|
|
|
|
<DateTime uri={uri} show={DateTime.SHOW_DATE} />
|
|
|
|
</span>
|
|
|
|
</FileTitle>
|
2021-05-12 20:26:47 +02:00
|
|
|
|
|
|
|
<div
|
|
|
|
className={classnames('post__info', {
|
|
|
|
'post__info--expanded': expand !== EXPAND.NONE,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<div className="post__info--grouped">
|
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
className="dim"
|
|
|
|
icon={ICONS.INFO}
|
|
|
|
aria-label={__('View claim details')}
|
|
|
|
onClick={() => handleExpand(EXPAND.FILE_DETAILS)}
|
|
|
|
/>
|
|
|
|
<Button button="link" className="dim" onClick={() => handleExpand(EXPAND.CREDIT_DETAILS)}>
|
|
|
|
<LbcSymbol postfix={expand === EXPAND.CREDIT_DETAILS ? __('Hide') : formattedAmount} />
|
|
|
|
</Button>
|
|
|
|
{claimIsMine && hasSupport && (
|
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
className="expandable__button"
|
|
|
|
icon={ICONS.UNLOCK}
|
|
|
|
aria-label={__('Unlock tips')}
|
|
|
|
onClick={() => {
|
|
|
|
doOpenModal(MODALS.LIQUIDATE_SUPPORTS, { uri });
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
2021-03-11 18:08:11 +01:00
|
|
|
<FileViewCount uri={uri} />
|
|
|
|
</div>
|
|
|
|
|
2021-05-12 20:26:47 +02:00
|
|
|
{expand === EXPAND.CREDIT_DETAILS && (
|
|
|
|
<div className="section post__info--credit-details">
|
|
|
|
<FileValues uri={uri} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{expand === EXPAND.FILE_DETAILS && (
|
|
|
|
<div className="section post__info--credit-details">
|
|
|
|
<ClaimTags uri={uri} type="large" />
|
|
|
|
<FileDetails uri={uri} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2021-03-11 18:08:11 +01:00
|
|
|
<FileAuthor uri={uri} />
|
|
|
|
|
|
|
|
<FileRenderInitiator uri={uri} />
|
|
|
|
<FileRenderInline uri={uri} />
|
|
|
|
<FileActions uri={uri} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PostViewer;
|