Refactor fileDescription

- user was unused
- only pass needed claim props
This commit is contained in:
Rafael 2022-02-01 17:23:48 -03:00 committed by Thomas Zarebczan
parent bc68207f40
commit 7b89db17bc
3 changed files with 45 additions and 44 deletions

View file

@ -1,22 +1,34 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { selectClaimForUri, makeSelectMetadataForUri, selectClaimIsMine } from 'redux/selectors/claims'; import { selectClaimForUri, selectClaimIsMine } from 'redux/selectors/claims';
import { makeSelectPendingAmountByUri } from 'redux/selectors/wallet'; import { makeSelectPendingAmountByUri } from 'redux/selectors/wallet';
import { doOpenModal } from 'redux/actions/app'; import { doOpenModal } from 'redux/actions/app';
import { selectUser } from 'redux/selectors/user';
import FileDescription from './view'; import FileDescription from './view';
import { getClaimMetadata } from 'util/claim';
const select = (state, props) => { const select = (state, props) => {
const claim = selectClaimForUri(state, props.uri); const { uri } = props;
const pendingAmount = makeSelectPendingAmountByUri(uri)(state);
const claim = selectClaimForUri(state, uri);
const metadata = getClaimMetadata(claim);
const description = metadata && metadata.description;
const amount = claim ? parseFloat(claim.amount) + parseFloat(pendingAmount || claim.meta.support_amount) : 0;
const hasSupport = claim && claim.meta && claim.meta.support_amount && Number(claim.meta.support_amount) > 0;
const isEmpty = !claim || !metadata;
return { return {
claim,
claimIsMine: selectClaimIsMine(state, claim), claimIsMine: selectClaimIsMine(state, claim),
metadata: makeSelectMetadataForUri(props.uri)(state), description,
user: selectUser(state), amount,
pendingAmount: makeSelectPendingAmountByUri(props.uri)(state), hasSupport,
isEmpty,
}; };
}; };
export default connect(select, { const perform = {
doOpenModal, doOpenModal,
})(FileDescription); };
export default connect(select, perform)(FileDescription);

View file

@ -13,36 +13,35 @@ import FileValues from 'component/fileValues';
type Props = { type Props = {
uri: string, uri: string,
claim: StreamClaim, expandOverride: boolean,
metadata: StreamMetadata, // redux
user: ?any, description?: string,
amount: number,
hasSupport?: boolean,
isEmpty: boolean,
claimIsMine: boolean,
pendingAmount: number, pendingAmount: number,
doOpenModal: (id: string, {}) => void, doOpenModal: (id: string, {}) => void,
claimIsMine: boolean,
expandOverride: boolean,
}; };
function FileDescription(props: Props) { export default function FileDescription(props: Props) {
const { uri, claim, metadata, pendingAmount, doOpenModal, claimIsMine, expandOverride } = props; const { uri, description, amount, hasSupport, isEmpty, doOpenModal, claimIsMine, expandOverride } = props;
const [expanded, setExpanded] = React.useState(false); const [expanded, setExpanded] = React.useState(false);
const [showCreditDetails, setShowCreditDetails] = React.useState(false); 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;
if (!claim || !metadata) { const formattedAmount = formatCredits(amount, 2, true);
if (isEmpty) {
return <span className="empty">{__('Empty claim or metadata info.')}</span>; return <span className="empty">{__('Empty claim or metadata info.')}</span>;
} }
const { description } = metadata;
return ( return (
<div> <>
<div <div
className={classnames({ className={classnames({
'media__info-text--contracted': !expanded && !expandOverride, 'media__info-text--contracted media__info-text--fade': !expanded && !expandOverride,
'media__info-text--expanded': expanded, 'media__info-text--expanded': expanded,
'media__info-text--fade': !expanded && !expandOverride,
})} })}
> >
{description && <MarkdownPreview className="markdown-preview--description" content={description} simpleLinks />} {description && <MarkdownPreview className="markdown-preview--description" content={description} simpleLinks />}
@ -52,13 +51,7 @@ function FileDescription(props: Props) {
<div className="card__bottom-actions"> <div className="card__bottom-actions">
{!expandOverride && ( {!expandOverride && (
<> <Button button="link" label={expanded ? __('Less') : __('More')} onClick={() => setExpanded(!expanded)} />
{expanded ? (
<Button button="link" label={__('Less')} onClick={() => setExpanded(!expanded)} />
) : (
<Button button="link" label={__('More')} onClick={() => setExpanded(!expanded)} />
)}
</>
)} )}
<div className="section__actions--no-margin"> <div className="section__actions--no-margin">
@ -68,24 +61,17 @@ function FileDescription(props: Props) {
className="expandable__button" className="expandable__button"
icon={ICONS.UNLOCK} icon={ICONS.UNLOCK}
aria-label={__('Unlock tips')} aria-label={__('Unlock tips')}
onClick={() => { onClick={() => doOpenModal(MODALS.LIQUIDATE_SUPPORTS, { uri })}
doOpenModal(MODALS.LIQUIDATE_SUPPORTS, { uri });
}}
/> />
)} )}
<Button button="link" onClick={() => setShowCreditDetails(!showCreditDetails)}> <Button button="link" onClick={() => setShowCreditDetails(!showCreditDetails)}>
<LbcSymbol postfix={showCreditDetails ? __('Hide') : formattedAmount} /> <LbcSymbol postfix={showCreditDetails ? __('Hide') : formattedAmount} />
</Button> </Button>
</div> </div>
</div> </div>
{showCreditDetails && ( {showCreditDetails && <FileValues uri={uri} />}
<div className="section"> </>
<FileValues uri={uri} />
</div>
)}
</div>
); );
} }
export default FileDescription;

View file

@ -90,8 +90,11 @@
} }
.media__info-text--fade { .media__info-text--fade {
-webkit-mask-image: -webkit-gradient(linear, left 55%, left bottom, from(rgba(0, 0, 0, 1)), to(rgba(0, 0, 0, 0)));
overflow-wrap: anywhere; overflow-wrap: anywhere;
// both needed for compatibility
-webkit-mask-image: -webkit-gradient(linear, left 55%, left bottom, from(rgba(0, 0, 0, 1)), to(rgba(0, 0, 0, 0)));
mask-image: -webkit-gradient(linear, left 55%, left bottom, from(rgba(0, 0, 0, 1)), to(rgba(0, 0, 0, 0)));
} }
.media__info-expand { .media__info-expand {