|
|
@ -2,11 +2,12 @@ import React, { |
|
|
|
memo, useEffect, useMemo, useState, |
|
|
|
} from 'react'; |
|
|
|
import { |
|
|
|
Dimmer, Grid, Image, Item, List, Placeholder, Segment, |
|
|
|
Dimmer, Grid, Icon, Image, Item, List, Placeholder, Segment, |
|
|
|
} from 'semantic-ui-react'; |
|
|
|
import PropTypes from 'prop-types'; |
|
|
|
import { useTranslation } from 'react-i18next'; |
|
|
|
import TimeAgo from 'react-timeago'; |
|
|
|
import { useHistory } from 'react-router'; |
|
|
|
import { useDispatch, useSelector } from 'react-redux'; |
|
|
|
import { Link } from 'react-router-dom'; |
|
|
|
import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; |
|
|
@ -33,6 +34,7 @@ const TopicListRow = (props) => { |
|
|
|
const topics = useSelector((state) => state.orbitData.topics); |
|
|
|
const users = useSelector((state) => state.orbitData.users); |
|
|
|
const dispatch = useDispatch(); |
|
|
|
const history = useHistory(); |
|
|
|
const { t } = useTranslation(); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
@ -40,7 +42,7 @@ const TopicListRow = (props) => { |
|
|
|
setTopicAuthorAddress(getTopicResults[topicCallHash].value[0]); |
|
|
|
setTopicAuthor(getTopicResults[topicCallHash].value[1]); |
|
|
|
setTimeAgo(getTopicResults[topicCallHash].value[2] * 1000); |
|
|
|
setNumberOfReplies(getTopicResults[topicCallHash].value[3].length); |
|
|
|
setNumberOfReplies(getTopicResults[topicCallHash].value[3].length - 1); |
|
|
|
} |
|
|
|
}, [getTopicResults, loading, topicCallHash]); |
|
|
|
|
|
|
@ -121,65 +123,69 @@ const TopicListRow = (props) => { |
|
|
|
return authorAvatar; |
|
|
|
}, [authorAvatar, topicAuthorAddress]); |
|
|
|
|
|
|
|
return useMemo(() => ( |
|
|
|
<Dimmer.Dimmable as={List.Item} blurring dimmed={loading} className="topic-row"> |
|
|
|
<Segment raised className="topic-row-segment" as="a"> |
|
|
|
<Grid doubling columns={2}> |
|
|
|
<Grid.Column width={1} className="topic-row-avatar"> |
|
|
|
<Item> |
|
|
|
{authorAvatarLink} |
|
|
|
</Item> |
|
|
|
</Grid.Column> |
|
|
|
<Grid.Column width={15} className="topic-row-content"> |
|
|
|
<Link to={`/topics/${topicId}`} onClick={stopClickPropagation}> |
|
|
|
<Grid verticalAlign="middle" columns={2}> |
|
|
|
<Grid.Row> |
|
|
|
<Grid.Column floated="left" width={14} className="topic-row-subject"> |
|
|
|
{topicSubject !== null |
|
|
|
? topicSubject |
|
|
|
: <Placeholder><Placeholder.Line length="very long" /></Placeholder>} |
|
|
|
</Grid.Column> |
|
|
|
<Grid.Column floated="right" width={2} textAlign="right"> |
|
|
|
<span className="topic-row-metadata"> |
|
|
|
{t('topic.list.row.topic.id', { id: topicId })} |
|
|
|
</span> |
|
|
|
</Grid.Column> |
|
|
|
</Grid.Row> |
|
|
|
<Grid.Row> |
|
|
|
<Grid.Column floated="left" width={14}> |
|
|
|
{topicAuthor !== null && timeAgo !== null |
|
|
|
? ( |
|
|
|
<div> |
|
|
|
<TimeAgo date={timeAgo} /> |
|
|
|
• |
|
|
|
<Link to={`/users/${topicAuthorAddress}`} onClick={stopClickPropagation}> |
|
|
|
{topicAuthor} |
|
|
|
</Link> |
|
|
|
</div> |
|
|
|
) |
|
|
|
: <Placeholder><Placeholder.Line length="long" /></Placeholder>} |
|
|
|
</Grid.Column> |
|
|
|
<Grid.Column floated="right" width={2} textAlign="right"> |
|
|
|
{numberOfReplies !== null |
|
|
|
? ( |
|
|
|
<span className="topic-row-metadata"> |
|
|
|
{t('topic.list.row.number.of.replies', { numberOfReplies })} |
|
|
|
</span> |
|
|
|
) |
|
|
|
: <Placeholder fluid><Placeholder.Line /></Placeholder>} |
|
|
|
</Grid.Column> |
|
|
|
</Grid.Row> |
|
|
|
</Grid> |
|
|
|
|
|
|
|
</Link> |
|
|
|
</Grid.Column> |
|
|
|
</Grid> |
|
|
|
|
|
|
|
</Segment> |
|
|
|
|
|
|
|
</Dimmer.Dimmable> |
|
|
|
|
|
|
|
), [authorAvatarLink, loading, numberOfReplies, t, timeAgo, topicAuthor, topicAuthorAddress, topicId, topicSubject]); |
|
|
|
return useMemo(() => { |
|
|
|
const handleTopicClick = () => { |
|
|
|
history.push(`/topics/${topicId}`); |
|
|
|
}; |
|
|
|
return ( |
|
|
|
<Dimmer.Dimmable as={List.Item} blurring dimmed={loading} className="topic-row" onClick={handleTopicClick}> |
|
|
|
<Segment className="topic-row-segment"> |
|
|
|
<Grid columns={2}> |
|
|
|
<Grid.Column width={1} className="topic-row-avatar"> |
|
|
|
<Item> |
|
|
|
{authorAvatarLink} |
|
|
|
</Item> |
|
|
|
</Grid.Column> |
|
|
|
<Grid.Column width={15} className="topic-row-content"> |
|
|
|
<Grid verticalAlign="middle" columns={2}> |
|
|
|
<Grid.Row> |
|
|
|
<Grid.Column floated="left" width={14} className="topic-row-subject"> |
|
|
|
{topicSubject !== null |
|
|
|
? topicSubject |
|
|
|
: <Placeholder><Placeholder.Line length="very long" /></Placeholder>} |
|
|
|
</Grid.Column> |
|
|
|
<Grid.Column floated="right" width={2} textAlign="right"> |
|
|
|
<span className="topic-row-metadata"> |
|
|
|
{t('topic.list.row.topic.id', { id: topicId })} |
|
|
|
</span> |
|
|
|
</Grid.Column> |
|
|
|
</Grid.Row> |
|
|
|
<Grid.Row> |
|
|
|
<Grid.Column floated="left" width={14}> |
|
|
|
{topicAuthor !== null && timeAgo !== null |
|
|
|
? ( |
|
|
|
<div> |
|
|
|
<TimeAgo date={timeAgo} /> |
|
|
|
• |
|
|
|
<Link to={`/users/${topicAuthorAddress}`} onClick={stopClickPropagation}> |
|
|
|
{topicAuthor} |
|
|
|
</Link> |
|
|
|
</div> |
|
|
|
) |
|
|
|
: <Placeholder><Placeholder.Line length="long" /></Placeholder>} |
|
|
|
</Grid.Column> |
|
|
|
<Grid.Column floated="right" width={2} textAlign="right"> |
|
|
|
{numberOfReplies !== null |
|
|
|
? ( |
|
|
|
<span className="topic-row-metadata"> |
|
|
|
<Icon name="reply" fitted /> |
|
|
|
|
|
|
|
{ numberOfReplies } |
|
|
|
</span> |
|
|
|
) |
|
|
|
: <Placeholder fluid className="replies-placeholder"><Placeholder.Line /></Placeholder>} |
|
|
|
</Grid.Column> |
|
|
|
</Grid.Row> |
|
|
|
</Grid> |
|
|
|
</Grid.Column> |
|
|
|
</Grid> |
|
|
|
|
|
|
|
</Segment> |
|
|
|
|
|
|
|
</Dimmer.Dimmable> |
|
|
|
|
|
|
|
); |
|
|
|
}, [authorAvatarLink, history, loading, numberOfReplies, t, timeAgo, topicAuthor, topicAuthorAddress, topicId, topicSubject]); |
|
|
|
}; |
|
|
|
|
|
|
|
TopicListRow.defaultProps = { |
|
|
|