Adds comment thumbnails
This commit is contained in:
parent
6018429e68
commit
171cfe31aa
3 changed files with 77 additions and 16 deletions
|
@ -1,7 +1,28 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
import {
|
||||||
|
doResolveUri,
|
||||||
|
makeSelectClaimIsPending,
|
||||||
|
makeSelectClaimForUri,
|
||||||
|
makeSelectThumbnailForUri,
|
||||||
|
makeSelectIsUriResolving,
|
||||||
|
selectChannelIsBlocked,
|
||||||
|
} from 'lbry-redux';
|
||||||
|
|
||||||
import Comment from './view';
|
import Comment from './view';
|
||||||
|
|
||||||
|
const select = (state, props) => ({
|
||||||
|
pending: props.authorUri && makeSelectClaimIsPending(props.authorUri)(state),
|
||||||
|
claim: props.authorUri && makeSelectClaimForUri(props.authorUri)(state),
|
||||||
|
isResolvingUri: props.authorUri && makeSelectIsUriResolving(props.authorUri)(state),
|
||||||
|
thumbnail: props.authorUri && makeSelectThumbnailForUri(props.authorUri)(state),
|
||||||
|
channelIsBlocked: props.authorUri && selectChannelIsBlocked(props.authorUri)(state),
|
||||||
|
});
|
||||||
|
|
||||||
|
const perform = dispatch => ({
|
||||||
|
resolveUri: uri => dispatch(doResolveUri(uri)),
|
||||||
|
});
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
null,
|
select,
|
||||||
null
|
perform
|
||||||
)(Comment);
|
)(Comment);
|
||||||
|
|
|
@ -1,33 +1,57 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React from 'react';
|
import React, { useEffect } from 'react';
|
||||||
|
import { isEmpty } from 'util/object';
|
||||||
import relativeDate from 'tiny-relative-date';
|
import relativeDate from 'tiny-relative-date';
|
||||||
import Button from 'component/button';
|
import Button from 'component/button';
|
||||||
import Expandable from 'component/expandable';
|
import Expandable from 'component/expandable';
|
||||||
import MarkdownPreview from 'component/common/markdown-preview';
|
import MarkdownPreview from 'component/common/markdown-preview';
|
||||||
|
import ChannelThumbnail from 'component/channelThumbnail';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
author: string,
|
author: string,
|
||||||
authorUri: string,
|
authorUri: string,
|
||||||
message: string,
|
message: string,
|
||||||
timePosted: number,
|
timePosted: number,
|
||||||
|
claim: ?Claim,
|
||||||
|
pending?: boolean,
|
||||||
|
resolveUri: string => void,
|
||||||
|
isResolvingUri: boolean,
|
||||||
|
channelIsBlocked: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
function Comment(props: Props) {
|
function Comment(props: Props) {
|
||||||
const { author, authorUri, timePosted, message } = props;
|
const {
|
||||||
|
author,
|
||||||
|
authorUri,
|
||||||
|
timePosted,
|
||||||
|
message,
|
||||||
|
pending,
|
||||||
|
claim,
|
||||||
|
isResolvingUri,
|
||||||
|
resolveUri,
|
||||||
|
channelIsBlocked,
|
||||||
|
} = props;
|
||||||
|
// to debounce subsequent requests
|
||||||
|
const shouldFetch =
|
||||||
|
claim === undefined || (claim !== null && claim.value_type === 'channel' && isEmpty(claim.meta) && !pending);
|
||||||
|
useEffect(() => {
|
||||||
|
// If author was extracted from the URI, then it must be valid.
|
||||||
|
if (authorUri && author && !isResolvingUri && shouldFetch) {
|
||||||
|
resolveUri(authorUri);
|
||||||
|
}
|
||||||
|
}, [isResolvingUri, shouldFetch, author, authorUri, resolveUri]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li className="comment">
|
<li className="comment">
|
||||||
<div className="comment__meta">
|
<div className="comment__author">
|
||||||
{!author ? (
|
<div className="comment__author-thumbnail">
|
||||||
<span className="comment__author">{__('Anonymous')}</span>
|
{authorUri ? <ChannelThumbnail uri={authorUri} obscure={channelIsBlocked} /> : <ChannelThumbnail />}
|
||||||
) : (
|
</div>
|
||||||
<Button
|
<Button
|
||||||
className="button--uri-indicator truncated-text comment__author"
|
className="button--uri-indicator truncated-text comment__author-name"
|
||||||
navigate={authorUri}
|
navigate={authorUri}
|
||||||
label={author}
|
label={author || __('Anonymous')}
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
|
|
||||||
<time className="comment__time" dateTime={timePosted}>
|
<time className="comment__time" dateTime={timePosted}>
|
||||||
{relativeDate(timePosted)}
|
{relativeDate(timePosted)}
|
||||||
</time>
|
</time>
|
||||||
|
|
|
@ -33,13 +33,29 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.comment__author {
|
.comment__author {
|
||||||
|
display: inherit;
|
||||||
|
justify-content: left;
|
||||||
|
vertical-align: center;
|
||||||
|
flex: initial;
|
||||||
|
padding-bottom: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment__author-thumbnail {
|
||||||
|
flex-shrink: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment__author-name {
|
||||||
|
margin-bottom: 1rem;
|
||||||
text-overflow: ellipsis; // This is where the magic happens
|
text-overflow: ellipsis; // This is where the magic happens
|
||||||
flex-basis: 400px;
|
flex-basis: 400px;
|
||||||
flex-shrink: 1;
|
flex-shrink: 1;
|
||||||
font-weight: var(--font-weight-bold);
|
font-weight: 600;
|
||||||
|
font-size: medium;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comment__time {
|
.comment__time {
|
||||||
|
flex: 1;
|
||||||
|
align-self: flex-start;
|
||||||
flex-basis: 200px;
|
flex-basis: 200px;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue