Browse Source

Add links to user profiles

develop
Apostolos Fanakis 4 years ago
parent
commit
af9ec235af
  1. 31
      packages/concordia-app/src/components/PostList/PostListRow/index.jsx
  2. 35
      packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx
  3. 8
      packages/concordia-app/src/views/Topic/TopicView/index.jsx

31
packages/concordia-app/src/components/PostList/PostListRow/index.jsx

@ -9,6 +9,7 @@ import { useTranslation } from 'react-i18next';
import moment from 'moment'; import moment from 'moment';
import { useHistory } from 'react-router'; import { useHistory } from 'react-router';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { Link } from 'react-router-dom';
import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions';
import { breeze } from '../../../redux/store'; import { breeze } from '../../../redux/store';
import './styles.css'; import './styles.css';
@ -90,10 +91,7 @@ const PostListRow = (props) => {
} }
}, [postAuthorAddress, users]); }, [postAuthorAddress, users]);
return useMemo(() => ( const authorAvatar = useMemo(() => (postAuthorMeta !== null && postAuthorMeta[USER_PROFILE_PICTURE]
<Dimmer.Dimmable as={Feed.Event} blurring dimmed={loading}>
<Feed.Label className="post-profile-picture">
{postAuthorMeta !== null && postAuthorMeta[USER_PROFILE_PICTURE]
? ( ? (
<Image <Image
avatar avatar
@ -107,7 +105,24 @@ const PostListRow = (props) => {
inverted inverted
color="black" color="black"
/> />
)} )), [postAuthorMeta]);
const authorAvatarLink = useMemo(() => {
if (postAuthorAddress) {
return (
<Link to={`/users/${postAuthorAddress}`}>
{authorAvatar}
</Link>
);
}
return authorAvatar;
}, [authorAvatar, postAuthorAddress]);
return useMemo(() => (
<Dimmer.Dimmable as={Feed.Event} blurring dimmed={loading}>
<Feed.Label className="post-profile-picture">
{authorAvatarLink}
</Feed.Label> </Feed.Label>
<Feed.Content> <Feed.Content>
<Feed.Summary> <Feed.Summary>
@ -119,12 +134,12 @@ const PostListRow = (props) => {
{t('post.list.row.post.id', { id: postIndexInTopic })} {t('post.list.row.post.id', { id: postIndexInTopic })}
</span> </span>
</div> </div>
{postAuthor !== null && timeAgo !== null {postAuthor !== null && setPostAuthorAddress !== null && timeAgo !== null
? ( ? (
<> <>
{t('post.list.row.author.pre')} {t('post.list.row.author.pre')}
&nbsp; &nbsp;
<Feed.User>{postAuthor}</Feed.User> <Feed.User as={Link} to={`/users/${postAuthorAddress}`}>{postAuthor}</Feed.User>
<Feed.Date className="post-summary-meta-date">{timeAgo}</Feed.Date> <Feed.Date className="post-summary-meta-date">{timeAgo}</Feed.Date>
</> </>
) )
@ -135,7 +150,7 @@ const PostListRow = (props) => {
</Feed.Extra> </Feed.Extra>
</Feed.Content> </Feed.Content>
</Dimmer.Dimmable> </Dimmer.Dimmable>
), [loading, postAuthor, postAuthorMeta, postContent, postIndexInTopic, postSubject, t, timeAgo]); ), [authorAvatarLink, loading, postAuthor, postContent, postIndexInTopic, postSubject, t, timeAgo]);
}; };
PostListRow.defaultProps = { PostListRow.defaultProps = {

35
packages/concordia-app/src/components/TopicList/TopicListRow/index.jsx

@ -9,6 +9,7 @@ import { useTranslation } from 'react-i18next';
import moment from 'moment'; import moment from 'moment';
import { useHistory } from 'react-router'; import { useHistory } from 'react-router';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { Link } from 'react-router-dom';
import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions';
import { breeze } from '../../../redux/store'; import { breeze } from '../../../redux/store';
import './styles.css'; import './styles.css';
@ -88,14 +89,11 @@ const TopicListRow = (props) => {
} }
}, [topicAuthorAddress, users]); }, [topicAuthorAddress, users]);
return useMemo(() => { const stopClickPropagation = (event) => {
const handleTopicClick = () => { event.stopPropagation();
history.push(`/topics/${topicId}`);
}; };
return ( const authorAvatar = useMemo(() => (topicAuthorMeta !== null && topicAuthorMeta[USER_PROFILE_PICTURE]
<Dimmer.Dimmable as={List.Item} onClick={handleTopicClick} blurring dimmed={loading} className="list-item">
{topicAuthorMeta !== null && topicAuthorMeta[USER_PROFILE_PICTURE]
? ( ? (
<Image <Image
className="profile-picture" className="profile-picture"
@ -111,7 +109,28 @@ const TopicListRow = (props) => {
color="black" color="black"
verticalAlign="middle" verticalAlign="middle"
/> />
)} )), [topicAuthorMeta]);
const authorAvatarLink = useMemo(() => {
if (topicAuthorAddress) {
return (
<Link to={`/users/${topicAuthorAddress}`} onClick={stopClickPropagation}>
{authorAvatar}
</Link>
);
}
return authorAvatar;
}, [authorAvatar, topicAuthorAddress]);
return useMemo(() => {
const handleTopicClick = () => {
history.push(`/topics/${topicId}`);
};
return (
<Dimmer.Dimmable as={List.Item} onClick={handleTopicClick} blurring dimmed={loading} className="list-item">
{authorAvatarLink}
<List.Content className="list-content"> <List.Content className="list-content">
<List.Header> <List.Header>
<Grid> <Grid>
@ -148,7 +167,7 @@ const TopicListRow = (props) => {
</List.Content> </List.Content>
</Dimmer.Dimmable> </Dimmer.Dimmable>
); );
}, [history, loading, numberOfReplies, t, timeAgo, topicAuthor, topicAuthorMeta, topicId, topicSubject]); }, [authorAvatarLink, history, loading, numberOfReplies, t, timeAgo, topicAuthor, topicId, topicSubject]);
}; };
TopicListRow.defaultProps = { TopicListRow.defaultProps = {

8
packages/concordia-app/src/views/Topic/TopicView/index.jsx

@ -5,6 +5,8 @@ import {
Container, Dimmer, Icon, Image, Placeholder, Step, Container, Dimmer, Icon, Image, Placeholder, Step,
} from 'semantic-ui-react'; } from 'semantic-ui-react';
import moment from 'moment'; import moment from 'moment';
import { useHistory } from 'react-router';
import { Link } from 'react-router-dom';
import { breeze, drizzle } from '../../../redux/store'; import { breeze, drizzle } from '../../../redux/store';
import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions'; import { FETCH_USER_DATABASE } from '../../../redux/actions/peerDbReplicationActions';
import './styles.css'; import './styles.css';
@ -36,7 +38,7 @@ const TopicView = (props) => {
const [timestamp, setTimestamp] = useState(initialTimestamp || null); const [timestamp, setTimestamp] = useState(initialTimestamp || null);
const [postIds, setPostIds] = useState(initialPostIds || null); const [postIds, setPostIds] = useState(initialPostIds || null);
const [topicSubject, setTopicSubject] = useState(null); const [topicSubject, setTopicSubject] = useState(null);
const history = useHistory();
const dispatch = useDispatch(); const dispatch = useDispatch();
useEffect(() => { useEffect(() => {
@ -114,6 +116,7 @@ const TopicView = (props) => {
> >
<Step.Group fluid> <Step.Group fluid>
<Step key="topic-header-step-user"> <Step key="topic-header-step-user">
<Link to={`/users/${topicAuthorAddress}`}>
{topicAuthorMeta !== null && topicAuthorMeta[USER_PROFILE_PICTURE] {topicAuthorMeta !== null && topicAuthorMeta[USER_PROFILE_PICTURE]
? ( ? (
<Image <Image
@ -129,13 +132,16 @@ const TopicView = (props) => {
color="black" color="black"
/> />
)} )}
</Link>
<Step.Content> <Step.Content>
<Step.Title> <Step.Title>
<Link to={`/users/${topicAuthorAddress}`}>
{topicAuthor || ( {topicAuthor || (
<Placeholder id="author-placeholder" inverted> <Placeholder id="author-placeholder" inverted>
<Placeholder.Line length="full" /> <Placeholder.Line length="full" />
</Placeholder> </Placeholder>
)} )}
</Link>
</Step.Title> </Step.Title>
</Step.Content> </Step.Content>
</Step> </Step>

Loading…
Cancel
Save