Browse Source

Add links to user profiles

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

51
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,24 +91,38 @@ const PostListRow = (props) => {
} }
}, [postAuthorAddress, users]); }, [postAuthorAddress, users]);
const authorAvatar = useMemo(() => (postAuthorMeta !== null && postAuthorMeta[USER_PROFILE_PICTURE]
? (
<Image
avatar
src={postAuthorMeta[USER_PROFILE_PICTURE]}
/>
)
: (
<Icon
name="user circle"
size="big"
inverted
color="black"
/>
)), [postAuthorMeta]);
const authorAvatarLink = useMemo(() => {
if (postAuthorAddress) {
return (
<Link to={`/users/${postAuthorAddress}`}>
{authorAvatar}
</Link>
);
}
return authorAvatar;
}, [authorAvatar, postAuthorAddress]);
return useMemo(() => ( return useMemo(() => (
<Dimmer.Dimmable as={Feed.Event} blurring dimmed={loading}> <Dimmer.Dimmable as={Feed.Event} blurring dimmed={loading}>
<Feed.Label className="post-profile-picture"> <Feed.Label className="post-profile-picture">
{postAuthorMeta !== null && postAuthorMeta[USER_PROFILE_PICTURE] {authorAvatarLink}
? (
<Image
avatar
src={postAuthorMeta[USER_PROFILE_PICTURE]}
/>
)
: (
<Icon
name="user circle"
size="big"
inverted
color="black"
/>
)}
</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 = {

55
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,6 +89,40 @@ const TopicListRow = (props) => {
} }
}, [topicAuthorAddress, users]); }, [topicAuthorAddress, users]);
const stopClickPropagation = (event) => {
event.stopPropagation();
};
const authorAvatar = useMemo(() => (topicAuthorMeta !== null && topicAuthorMeta[USER_PROFILE_PICTURE]
? (
<Image
className="profile-picture"
avatar
src={topicAuthorMeta[USER_PROFILE_PICTURE]}
/>
)
: (
<List.Icon
name="user circle"
size="big"
inverted
color="black"
verticalAlign="middle"
/>
)), [topicAuthorMeta]);
const authorAvatarLink = useMemo(() => {
if (topicAuthorAddress) {
return (
<Link to={`/users/${topicAuthorAddress}`} onClick={stopClickPropagation}>
{authorAvatar}
</Link>
);
}
return authorAvatar;
}, [authorAvatar, topicAuthorAddress]);
return useMemo(() => { return useMemo(() => {
const handleTopicClick = () => { const handleTopicClick = () => {
history.push(`/topics/${topicId}`); history.push(`/topics/${topicId}`);
@ -95,23 +130,7 @@ const TopicListRow = (props) => {
return ( return (
<Dimmer.Dimmable as={List.Item} onClick={handleTopicClick} blurring dimmed={loading} className="list-item"> <Dimmer.Dimmable as={List.Item} onClick={handleTopicClick} blurring dimmed={loading} className="list-item">
{topicAuthorMeta !== null && topicAuthorMeta[USER_PROFILE_PICTURE] {authorAvatarLink}
? (
<Image
className="profile-picture"
avatar
src={topicAuthorMeta[USER_PROFILE_PICTURE]}
/>
)
: (
<List.Icon
name="user circle"
size="big"
inverted
color="black"
verticalAlign="middle"
/>
)}
<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 = {

48
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,28 +116,32 @@ const TopicView = (props) => {
> >
<Step.Group fluid> <Step.Group fluid>
<Step key="topic-header-step-user"> <Step key="topic-header-step-user">
{topicAuthorMeta !== null && topicAuthorMeta[USER_PROFILE_PICTURE] <Link to={`/users/${topicAuthorAddress}`}>
? ( {topicAuthorMeta !== null && topicAuthorMeta[USER_PROFILE_PICTURE]
<Image ? (
avatar <Image
src={topicAuthorMeta[USER_PROFILE_PICTURE]} avatar
/> src={topicAuthorMeta[USER_PROFILE_PICTURE]}
) />
: ( )
<Icon : (
name="user circle" <Icon
size="big" name="user circle"
inverted size="big"
color="black" inverted
/> color="black"
)} />
)}
</Link>
<Step.Content> <Step.Content>
<Step.Title> <Step.Title>
{topicAuthor || ( <Link to={`/users/${topicAuthorAddress}`}>
<Placeholder id="author-placeholder" inverted> {topicAuthor || (
<Placeholder.Line length="full" /> <Placeholder id="author-placeholder" inverted>
</Placeholder> <Placeholder.Line length="full" />
)} </Placeholder>
)}
</Link>
</Step.Title> </Step.Title>
</Step.Content> </Step.Content>
</Step> </Step>

Loading…
Cancel
Save