Skip to content

Commit edd3f73

Browse files
authored
feat: made user profile image visible (#778)
* feat: made user profile image visible * refactor: updated selector name * refactor: updated selector name
1 parent 33375a5 commit edd3f73

File tree

6 files changed

+38
-12
lines changed

6 files changed

+38
-12
lines changed

src/discussions/learners/data/selectors.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ export const selectUsernameSearch = () => state => state.learners.usernameSearch
1212
export const selectLearnerSorting = () => state => state.learners.sortedBy;
1313

1414
export const selectLearnerNextPage = () => state => state.learners.nextPage;
15+
16+
export const selectLearnerAvatar = author => state => (
17+
state.learners.learnerProfiles[author]?.profileImage?.imageUrlLarge
18+
);

src/discussions/learners/learner/LearnerAvatar.jsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33

44
import { Avatar } from '@openedx/paragon';
5+
import { useSelector } from 'react-redux';
56

6-
const LearnerAvatar = ({ username }) => (
7-
<div className="mr-3 mt-1">
8-
<Avatar
9-
size="sm"
10-
alt={username}
11-
style={{
12-
height: '2rem',
13-
width: '2rem',
14-
}}
15-
/>
16-
</div>
17-
);
7+
import { selectLearnerAvatar } from '../data/selectors';
8+
9+
const LearnerAvatar = ({ username }) => {
10+
const learnerAvatar = useSelector(selectLearnerAvatar(username));
11+
return (
12+
<div className="mr-3 mt-1">
13+
<Avatar
14+
size="sm"
15+
alt={username}
16+
src={learnerAvatar}
17+
style={{
18+
height: '2rem',
19+
width: '2rem',
20+
}}
21+
/>
22+
</div>
23+
);
24+
};
1825

1926
LearnerAvatar.propTypes = {
2027
username: PropTypes.string.isRequired,

src/discussions/post-comments/comments/comment/CommentHeader.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import PropTypes from 'prop-types';
33

44
import { Avatar } from '@openedx/paragon';
55
import classNames from 'classnames';
6+
import { useSelector } from 'react-redux';
67

78
import { AvatarOutlineAndLabelColors } from '../../../../data/constants';
89
import { AuthorLabel } from '../../../common';
910
import { useAlertBannerVisible } from '../../../data/hooks';
11+
import { selectAuthorAvatar } from '../../../posts/data/selectors';
1012

1113
const CommentHeader = ({
1214
author,
@@ -23,6 +25,7 @@ const CommentHeader = ({
2325
lastEdit,
2426
closed,
2527
});
28+
const authorAvatar = useSelector(selectAuthorAvatar(author));
2629

2730
return (
2831
<div className={classNames('d-flex flex-row justify-content-between', {
@@ -33,6 +36,7 @@ const CommentHeader = ({
3336
<Avatar
3437
className={`border-0 ml-0.5 mr-2.5 ${colorClass ? `outline-${colorClass}` : 'outline-anonymous'}`}
3538
alt={author}
39+
src={authorAvatar?.imageUrlSmall}
3640
style={{
3741
width: '32px',
3842
height: '32px',

src/discussions/post-comments/comments/comment/Reply.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import timeLocale from '../../../common/time-locale';
1616
import { ContentTypes } from '../../../data/constants';
1717
import { useAlertBannerVisible } from '../../../data/hooks';
18+
import { selectAuthorAvatar } from '../../../posts/data/selectors';
1819
import { selectCommentOrResponseById } from '../../data/selectors';
1920
import { editComment, removeComment } from '../../data/thunks';
2021
import messages from '../../messages';
@@ -38,6 +39,7 @@ const Reply = ({ responseId }) => {
3839
lastEdit,
3940
closed,
4041
});
42+
const authorAvatar = useSelector(selectAuthorAvatar(author));
4143

4244
const handleDeleteConfirmation = useCallback(() => {
4345
dispatch(removeComment(id));
@@ -121,6 +123,7 @@ const Reply = ({ responseId }) => {
121123
<Avatar
122124
className={`ml-0.5 mt-0.5 border-0 ${colorClass ? `outline-${colorClass}` : 'outline-anonymous'}`}
123125
alt={author}
126+
src={authorAvatar?.imageUrlSmall}
124127
style={{
125128
width: '32px',
126129
height: '32px',

src/discussions/posts/data/selectors.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ export const selectThreadSorting = () => state => state.threads.sortedBy;
5656
export const selectThreadFilters = () => state => state.threads.filters;
5757

5858
export const selectThreadNextPage = () => state => state.threads.nextPage;
59+
60+
export const selectAuthorAvatar = author => state => (
61+
state.threads.avatars?.[author]?.profile.image
62+
);

src/discussions/posts/post/PostHeader.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ import PropTypes from 'prop-types';
44
import { Avatar, Badge, Icon } from '@openedx/paragon';
55
import { Question } from '@openedx/paragon/icons';
66
import classNames from 'classnames';
7+
import { useSelector } from 'react-redux';
78

89
import { useIntl } from '@edx/frontend-platform/i18n';
910

1011
import { AvatarOutlineAndLabelColors, ThreadType } from '../../../data/constants';
1112
import { AuthorLabel } from '../../common';
1213
import { useAlertBannerVisible } from '../../data/hooks';
14+
import { selectAuthorAvatar } from '../data/selectors';
1315
import messages from './messages';
1416

1517
export const PostAvatar = React.memo(({
1618
author, postType, authorLabel, fromPostLink, read,
1719
}) => {
1820
const outlineColor = AvatarOutlineAndLabelColors[authorLabel];
21+
const authorAvatars = useSelector(selectAuthorAvatar(author));
1922

2023
const avatarSize = useMemo(() => {
2124
let size = '2rem';
@@ -60,6 +63,7 @@ export const PostAvatar = React.memo(({
6063
width: avatarSize,
6164
}}
6265
alt={author}
66+
src={authorAvatars?.imageUrlSmall}
6367
/>
6468
</div>
6569
);

0 commit comments

Comments
 (0)