2020-03-25 04:15:05 +01:00
|
|
|
// @flow
|
2020-09-30 22:46:20 +02:00
|
|
|
import React from 'react';
|
|
|
|
import classnames from 'classnames';
|
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-03-25 04:15:05 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
|
|
|
claim: StreamClaim,
|
|
|
|
metadata: StreamMetadata,
|
|
|
|
user: ?any,
|
|
|
|
tags: any,
|
|
|
|
};
|
|
|
|
|
2020-09-30 22:46:20 +02:00
|
|
|
function FileDescription(props: Props) {
|
|
|
|
const { uri, claim, metadata, tags } = props;
|
|
|
|
const [expanded, setExpanded] = React.useState(false);
|
|
|
|
const [hasOverflow, setHasOverflow] = React.useState(false);
|
|
|
|
const [hasCalculatedOverflow, setHasCalculatedOverflow] = React.useState(false);
|
|
|
|
const descriptionRef = React.useRef();
|
2020-03-25 04:15:05 +01:00
|
|
|
|
2020-09-30 22:46:20 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
if (descriptionRef && descriptionRef.current) {
|
|
|
|
const element = descriptionRef.current;
|
|
|
|
const isOverflowing = element.scrollHeight > element.clientHeight;
|
|
|
|
setHasOverflow(isOverflowing);
|
|
|
|
setHasCalculatedOverflow(true);
|
2020-03-25 04:15:05 +01:00
|
|
|
}
|
2020-09-30 22:46:20 +02:00
|
|
|
}, [descriptionRef]);
|
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;
|
|
|
|
|
|
|
|
if (!description && !(tags && tags.length)) return null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div
|
|
|
|
ref={descriptionRef}
|
2020-09-11 17:42:20 +02:00
|
|
|
className={classnames({
|
|
|
|
'media__info-text--contracted': !expanded,
|
|
|
|
'media__info-text--expanded': expanded,
|
|
|
|
'media__info-text--fade': hasOverflow && !expanded,
|
|
|
|
})}
|
2020-09-30 22:46:20 +02:00
|
|
|
>
|
|
|
|
<MarkdownPreview className="markdown-preview--description" content={description} />
|
|
|
|
<ClaimTags uri={uri} type="large" />
|
|
|
|
</div>
|
|
|
|
{hasCalculatedOverflow && hasOverflow && (
|
|
|
|
<div className="media__info-expand">
|
|
|
|
{expanded ? (
|
|
|
|
<Button button="link" label={__('Less')} onClick={() => setExpanded(!expanded)} />
|
|
|
|
) : (
|
|
|
|
<Button button="link" label={__('More')} onClick={() => setExpanded(!expanded)} />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
2020-03-25 04:15:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default FileDescription;
|