2019-06-13 04:26:40 +02:00
|
|
|
// @flow
|
|
|
|
import * as React from 'react';
|
|
|
|
import UriIndicator from 'component/uriIndicator';
|
|
|
|
import TruncatedText from 'component/common/truncated-text';
|
|
|
|
import MarkdownPreview from 'component/common/markdown-preview';
|
|
|
|
import { withRouter } from 'react-router-dom';
|
2019-12-02 18:30:08 +01:00
|
|
|
import { formatLbryUrlForWeb } from 'util/url';
|
2020-10-20 19:10:02 +02:00
|
|
|
import { parseURI } from 'lbry-redux';
|
|
|
|
import classnames from 'classnames';
|
2019-06-13 04:26:40 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
|
|
|
title: ?string,
|
|
|
|
thumbnail: ?string,
|
|
|
|
description: ?string,
|
2021-06-11 08:06:29 +02:00
|
|
|
history: { push: (string) => void },
|
2019-06-13 04:26:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class PreviewLink extends React.PureComponent<Props> {
|
|
|
|
handleClick = () => {
|
|
|
|
const { uri, history } = this.props;
|
2019-12-02 18:30:08 +01:00
|
|
|
history.push(formatLbryUrlForWeb(uri));
|
2019-06-13 04:26:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { uri, title, description, thumbnail } = this.props;
|
2020-10-20 19:10:02 +02:00
|
|
|
const { isChannel } = parseURI(uri);
|
2019-06-13 04:26:40 +02:00
|
|
|
const placeholder = 'static/img/placeholder.png';
|
|
|
|
|
|
|
|
const thumbnailStyle = {
|
|
|
|
backgroundImage: `url(${thumbnail || placeholder})`,
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2020-10-08 19:36:57 +02:00
|
|
|
<span className="preview-link" role="button" onClick={this.handleClick}>
|
|
|
|
<span className="claim-preview">
|
2020-10-20 19:10:02 +02:00
|
|
|
<span
|
|
|
|
style={thumbnailStyle}
|
|
|
|
className={classnames('preview-link__thumbnail media__thumb', {
|
|
|
|
'preview-link__thumbnail--channel': isChannel,
|
|
|
|
})}
|
|
|
|
/>
|
2020-10-08 19:36:57 +02:00
|
|
|
<span className="claim-preview-metadata">
|
|
|
|
<span className="claim-preview-info">
|
|
|
|
<span className="claim-preview__title">
|
2019-06-21 03:00:52 +02:00
|
|
|
<TruncatedText text={title} lines={1} />
|
2019-06-13 04:26:40 +02:00
|
|
|
</span>
|
|
|
|
</span>
|
2020-10-08 19:36:57 +02:00
|
|
|
<span className="media__subtitle">
|
2019-06-21 03:00:52 +02:00
|
|
|
<UriIndicator uri={uri} link />
|
|
|
|
</span>
|
2020-10-08 19:36:57 +02:00
|
|
|
<span className="claim-preview-properties">
|
|
|
|
<span className="preview-link__description media__subtitle">
|
2019-06-21 03:00:52 +02:00
|
|
|
<TruncatedText lines={2} showTooltip={false}>
|
2019-12-03 17:41:44 +01:00
|
|
|
<MarkdownPreview content={description} strip />
|
2019-06-21 03:00:52 +02:00
|
|
|
</TruncatedText>
|
|
|
|
</span>
|
2019-06-13 04:26:40 +02:00
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withRouter(PreviewLink);
|