import React, { useMemo } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { useSelector } from 'react-redux'; import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; import { Avatar, Badge, Icon } from '@edx/paragon'; import { Issue, Question } from '../../../components/icons'; import { AvatarOutlineAndLabelColors, ThreadType } from '../../../data/constants'; import { ActionsDropdown, AuthorLabel } from '../../common'; import { useAlertBannerVisible } from '../../data/hooks'; import { selectAuthorAvatars } from '../data/selectors'; import messages from './messages'; import { postShape } from './proptypes'; export function PostAvatar({ post, authorLabel, fromPostLink, read, }) { const authorAvatars = useSelector(selectAuthorAvatars(post.author)); const outlineColor = AvatarOutlineAndLabelColors[authorLabel]; const avatarSize = useMemo(() => { let size = '1.75rem'; if (post.type === ThreadType.DISCUSSION && !fromPostLink) { size = '2.375rem'; } else if (post.type === ThreadType.QUESTION) { size = '1.375rem'; } return size; }, [post.type]); const avatarSpacing = useMemo(() => { let spacing = 'mr-3 '; if (post.type === ThreadType.DISCUSSION && fromPostLink) { spacing += 'pt-2 ml-0.5'; } else if (post.type === ThreadType.DISCUSSION) { spacing += 'ml-0.5 mt-0.5'; } return spacing; }, [post.type]); return (
{post.type === ThreadType.QUESTION && ( )}
); } PostAvatar.propTypes = { post: postShape.isRequired, authorLabel: PropTypes.string, fromPostLink: PropTypes.bool, read: PropTypes.bool, }; PostAvatar.defaultProps = { authorLabel: null, fromPostLink: false, read: false, }; function PostHeader({ intl, post, preview, actionHandlers, }) { const showAnsweredBadge = preview && post.hasEndorsed && post.type === ThreadType.QUESTION; const authorLabelColor = AvatarOutlineAndLabelColors[post.authorLabel]; const hasAnyAlert = useAlertBannerVisible(post); return (
{preview ? (
{post.title}
{showAnsweredBadge && {intl.formatMessage(messages.answered)}}
) :

{post.title}

}
{!preview && (
)}
); } PostHeader.propTypes = { intl: intlShape.isRequired, post: postShape.isRequired, preview: PropTypes.bool, actionHandlers: PropTypes.objectOf(PropTypes.func).isRequired, }; PostHeader.defaultProps = { preview: false, }; export default injectIntl(PostHeader);