Skip to content

Commit

Permalink
feat: add profile image to avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
vladislavkeblysh authored and dyudyunov committed Nov 8, 2024
1 parent af6cd18 commit 3ace4fd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/discussions/posts/post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Post = ({ handleAddResponseButton }) => {
const {
topicId, abuseFlagged, closed, pinned, voted, hasEndorsed, following, closedBy, voteCount, groupId, groupName,
closeReason, authorLabel, type: postType, author, title, createdAt, renderedBody, lastEdit, editByLabel,
closedByLabel,
closedByLabel, users: postUsers,
} = useSelector(selectThread(postId));
const intl = useIntl();
const location = useLocation();
Expand Down Expand Up @@ -182,6 +182,7 @@ const Post = ({ handleAddResponseButton }) => {
lastEdit={lastEdit}
postType={postType}
title={title}
postUsers={postUsers}
/>
<div className="d-flex mt-14px text-break font-style text-primary-500">
<HTMLLoader htmlNode={renderedBody} componentId="post" cssClassName="html-loader w-100" testId={postId} />
Expand Down
10 changes: 8 additions & 2 deletions src/discussions/posts/post/PostHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useAlertBannerVisible } from '../../data/hooks';
import messages from './messages';

export const PostAvatar = React.memo(({
author, postType, authorLabel, fromPostLink, read,
author, postType, authorLabel, fromPostLink, read, postUsers,
}) => {
const outlineColor = AvatarOutlineAndLabelColors[authorLabel];

Expand All @@ -37,6 +37,8 @@ export const PostAvatar = React.memo(({
return spacing;
}, [postType]);

const profileImage = Object.values(postUsers)[0].profile.image;

return (
<div className={avatarSpacing}>
{postType === ThreadType.QUESTION && (
Expand All @@ -59,6 +61,7 @@ export const PostAvatar = React.memo(({
height: avatarSize,
width: avatarSize,
}}
src={profileImage?.hasImage ? profileImage?.imageUrlSmall : undefined}
alt={author}
/>
</div>
Expand All @@ -71,6 +74,7 @@ PostAvatar.propTypes = {
authorLabel: PropTypes.string,
fromPostLink: PropTypes.bool,
read: PropTypes.bool,
postUsers: PropTypes.shape({}).isRequired,
};

PostAvatar.defaultProps = {
Expand All @@ -90,6 +94,7 @@ const PostHeader = ({
title,
postType,
preview,
postUsers,
}) => {
const intl = useIntl();
const showAnsweredBadge = preview && hasEndorsed && postType === ThreadType.QUESTION;
Expand All @@ -101,7 +106,7 @@ const PostHeader = ({
return (
<div className={classNames('d-flex flex-fill mw-100', { 'mt-10px': hasAnyAlert && !preview })}>
<div className="flex-shrink-0">
<PostAvatar postType={postType} author={author} authorLabel={authorLabel} />
<PostAvatar postType={postType} author={author} authorLabel={authorLabel} postUsers={postUsers} />
</div>
<div className="align-items-center d-flex flex-row">
<div className="d-flex flex-column justify-content-start mw-100">
Expand Down Expand Up @@ -151,6 +156,7 @@ PostHeader.propTypes = {
reason: PropTypes.string,
}),
closed: PropTypes.bool,
postUsers: PropTypes.shape({}).isRequired,
};

PostHeader.defaultProps = {
Expand Down
2 changes: 2 additions & 0 deletions src/discussions/posts/post/PostLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const PostLink = ({
const {
topicId, hasEndorsed, type, author, authorLabel, abuseFlagged, abuseFlaggedCount, read, commentCount,
unreadCommentCount, id, pinned, previewBody, title, voted, voteCount, following, groupId, groupName, createdAt,
users: postUsers,
} = useSelector(selectThread(postId));
const { pathname } = discussionsPath(Routes.COMMENTS.PAGES[page], {
0: enableInContextSidebar ? 'in-context' : undefined,
Expand Down Expand Up @@ -83,6 +84,7 @@ const PostLink = ({
authorLabel={authorLabel}
fromPostLink
read={isPostRead}
postUsers={postUsers}
/>
<div className="d-flex flex-column flex-fill" style={{ minWidth: 0 }}>
<div className="d-flex flex-column justify-content-start mw-100 flex-fill" style={{ marginBottom: '-3px' }}>
Expand Down

0 comments on commit 3ace4fd

Please sign in to comment.