|
@ -1,8 +1,8 @@ |
|
|
import React, { |
|
|
import React, { |
|
|
memo, useEffect, useMemo, useState, |
|
|
memo, useEffect, useMemo, useState, useCallback, |
|
|
} from 'react'; |
|
|
} from 'react'; |
|
|
import { |
|
|
import { |
|
|
Dimmer, Icon, Image, Feed, Placeholder, |
|
|
Dimmer, Icon, Image, Feed, Placeholder, Ref, |
|
|
} from 'semantic-ui-react'; |
|
|
} from 'semantic-ui-react'; |
|
|
import PropTypes from 'prop-types'; |
|
|
import PropTypes from 'prop-types'; |
|
|
import { useTranslation } from 'react-i18next'; |
|
|
import { useTranslation } from 'react-i18next'; |
|
@ -22,12 +22,13 @@ const { orbit } = breeze; |
|
|
|
|
|
|
|
|
const PostListRow = (props) => { |
|
|
const PostListRow = (props) => { |
|
|
const { |
|
|
const { |
|
|
id: postId, postIndexInTopic, postCallHash, loading, |
|
|
id: postId, postIndex, postCallHash, loading, focus, |
|
|
} = props; |
|
|
} = props; |
|
|
const getPostResults = useSelector((state) => state.contracts[FORUM_CONTRACT].getPost); |
|
|
const getPostResults = useSelector((state) => state.contracts[FORUM_CONTRACT].getPost); |
|
|
const [postAuthorAddress, setPostAuthorAddress] = useState(null); |
|
|
const [postAuthorAddress, setPostAuthorAddress] = useState(null); |
|
|
const [postAuthor, setPostAuthor] = useState(null); |
|
|
const [postAuthor, setPostAuthor] = useState(null); |
|
|
const [timeAgo, setTimeAgo] = useState(null); |
|
|
const [timeAgo, setTimeAgo] = useState(null); |
|
|
|
|
|
const [topicId, setTopicId] = useState(null); |
|
|
const [postContent, setPostContent] = useState(null); |
|
|
const [postContent, setPostContent] = useState(null); |
|
|
const [postAuthorMeta, setPostAuthorMeta] = useState(null); |
|
|
const [postAuthorMeta, setPostAuthorMeta] = useState(null); |
|
|
const userAddress = useSelector((state) => state.user.address); |
|
|
const userAddress = useSelector((state) => state.user.address); |
|
@ -41,6 +42,7 @@ const PostListRow = (props) => { |
|
|
setPostAuthorAddress(getPostResults[postCallHash].value[0]); |
|
|
setPostAuthorAddress(getPostResults[postCallHash].value[0]); |
|
|
setPostAuthor(getPostResults[postCallHash].value[1]); |
|
|
setPostAuthor(getPostResults[postCallHash].value[1]); |
|
|
setTimeAgo(getPostResults[postCallHash].value[2] * 1000); |
|
|
setTimeAgo(getPostResults[postCallHash].value[2] * 1000); |
|
|
|
|
|
setTopicId(getPostResults[postCallHash].value[3]); |
|
|
} |
|
|
} |
|
|
}, [getPostResults, loading, postCallHash]); |
|
|
}, [getPostResults, loading, postCallHash]); |
|
|
|
|
|
|
|
@ -116,18 +118,31 @@ const PostListRow = (props) => { |
|
|
return authorAvatar; |
|
|
return authorAvatar; |
|
|
}, [authorAvatar, postAuthorAddress]); |
|
|
}, [authorAvatar, postAuthorAddress]); |
|
|
|
|
|
|
|
|
|
|
|
const focusRef = useCallback((node) => { |
|
|
|
|
|
if (focus && node !== null) { |
|
|
|
|
|
node.scrollIntoView({ behavior: 'smooth' }); |
|
|
|
|
|
} |
|
|
|
|
|
}, [focus]); |
|
|
|
|
|
|
|
|
return useMemo(() => ( |
|
|
return useMemo(() => ( |
|
|
<Dimmer.Dimmable as={Feed.Event} blurring dimmed={loading}> |
|
|
<Dimmer.Dimmable |
|
|
<Feed.Label className="post-profile-picture"> |
|
|
as={Feed.Event} |
|
|
{authorAvatarLink} |
|
|
blurring |
|
|
</Feed.Label> |
|
|
dimmed={loading} |
|
|
|
|
|
id={`post-${postId}`} |
|
|
|
|
|
> |
|
|
|
|
|
<Ref innerRef={focusRef}> |
|
|
|
|
|
<Feed.Label className="post-profile-picture"> |
|
|
|
|
|
{authorAvatarLink} |
|
|
|
|
|
</Feed.Label> |
|
|
|
|
|
</Ref> |
|
|
<Feed.Content> |
|
|
<Feed.Content> |
|
|
<Feed.Summary> |
|
|
<Feed.Summary> |
|
|
<div> |
|
|
<Link to={`/topics/${topicId}/#post-${postId}`}> |
|
|
<span className="post-summary-meta-index"> |
|
|
<span className="post-summary-meta-index"> |
|
|
{t('post.list.row.post.id', { id: postIndexInTopic })} |
|
|
{t('post.list.row.post.id', { id: postIndex })} |
|
|
</span> |
|
|
</span> |
|
|
</div> |
|
|
</Link> |
|
|
{postAuthor !== null && setPostAuthorAddress !== null && timeAgo !== null |
|
|
{postAuthor !== null && setPostAuthorAddress !== null && timeAgo !== null |
|
|
? ( |
|
|
? ( |
|
|
<> |
|
|
<> |
|
@ -147,19 +162,22 @@ const PostListRow = (props) => { |
|
|
</Feed.Content> |
|
|
</Feed.Content> |
|
|
</Dimmer.Dimmable> |
|
|
</Dimmer.Dimmable> |
|
|
), [ |
|
|
), [ |
|
|
authorAvatarLink, loading, postAuthor, postAuthorAddress, postContent, postIndexInTopic, t, timeAgo, |
|
|
authorAvatarLink, focusRef, loading, postAuthor, postAuthorAddress, postContent, postId, postIndex, t, timeAgo, |
|
|
|
|
|
topicId, |
|
|
]); |
|
|
]); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
PostListRow.defaultProps = { |
|
|
PostListRow.defaultProps = { |
|
|
loading: false, |
|
|
loading: false, |
|
|
|
|
|
focus: false, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
PostListRow.propTypes = { |
|
|
PostListRow.propTypes = { |
|
|
id: PropTypes.number.isRequired, |
|
|
id: PropTypes.number.isRequired, |
|
|
postIndexInTopic: PropTypes.number.isRequired, |
|
|
postIndex: PropTypes.number.isRequired, |
|
|
postCallHash: PropTypes.string, |
|
|
postCallHash: PropTypes.string, |
|
|
loading: PropTypes.bool, |
|
|
loading: PropTypes.bool, |
|
|
|
|
|
focus: PropTypes.bool, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
export default memo(PostListRow); |
|
|
export default memo(PostListRow); |
|
|