From 6886f389dd3c52408fdf48d7e44a01d6729f2264 Mon Sep 17 00:00:00 2001 From: Syed Ali Abbas Zaidi <88369802+Syed-Ali-Abbas-Zaidi@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:08:35 +0500 Subject: [PATCH] [MM-57715] Convert `./components/common/comment_icon.tsx` from Class Component to Function Component (#26727) * [MM-57715] Convert `./components/common/comment_icon.tsx` from Class Component to Function Component * :fix: failing types issue --- .../src/components/common/comment_icon.tsx | 116 +++++++++--------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/webapp/channels/src/components/common/comment_icon.tsx b/webapp/channels/src/components/common/comment_icon.tsx index 7842f3b844..c2faa8b5b6 100644 --- a/webapp/channels/src/components/common/comment_icon.tsx +++ b/webapp/channels/src/components/common/comment_icon.tsx @@ -2,77 +2,77 @@ // See LICENSE.txt for license information. import React from 'react'; -import {FormattedMessage} from 'react-intl'; +import {FormattedMessage, useIntl} from 'react-intl'; import OverlayTrigger from 'components/overlay_trigger'; import Tooltip from 'components/tooltip'; import ReplyIcon from 'components/widgets/icons/reply_icon'; import type {Locations} from 'utils/constants'; -import {localizeMessage} from 'utils/utils'; type Props = { - location: keyof typeof Locations; - handleCommentClick: React.EventHandler; - searchStyle: string; - commentCount: number; + location?: keyof typeof Locations; + handleCommentClick?: React.EventHandler; + searchStyle?: string; + commentCount?: number; postId?: string; extraClass: string; } -export default class CommentIcon extends React.PureComponent { - public static defaultProps: Partial = { - location: 'CENTER', - searchStyle: '', - commentCount: 0, - extraClass: '', - }; +const CommentIcon = ({ + location = 'CENTER', + searchStyle = '', + commentCount = 0, + extraClass = '', + handleCommentClick, + postId, +}: Props) => { + const intl = useIntl(); - public render(): JSX.Element { - let commentCountSpan: JSX.Element | null = null; - let iconStyle = 'post-menu__item post-menu__item--wide'; - if (this.props.commentCount > 0) { - iconStyle += ' post-menu__item--show'; - commentCountSpan = ( - - {this.props.commentCount} - - ); - } else if (this.props.searchStyle !== '') { - iconStyle = iconStyle + ' ' + this.props.searchStyle; - } - - const tooltip = ( - - - - ); - - return ( - - - + let commentCountSpan: JSX.Element | null = null; + let iconStyle = 'post-menu__item post-menu__item--wide'; + if (commentCount > 0) { + iconStyle += ' post-menu__item--show'; + commentCountSpan = ( + + {commentCount} + ); + } else if (searchStyle !== '') { + iconStyle = `${iconStyle} ${searchStyle}`; } -} + const tooltip = ( + + + + ); + + return ( + + + + ); +}; + +export default CommentIcon;