diff --git a/webapp/channels/src/components/channel_header_dropdown/__snapshots__/channel_header_dropdown.test.tsx.snap b/webapp/channels/src/components/channel_header_dropdown/__snapshots__/channel_header_dropdown.test.tsx.snap index 7ca4af943d..743d515c4d 100644 --- a/webapp/channels/src/components/channel_header_dropdown/__snapshots__/channel_header_dropdown.test.tsx.snap +++ b/webapp/channels/src/components/channel_header_dropdown/__snapshots__/channel_header_dropdown.test.tsx.snap @@ -48,7 +48,7 @@ exports[`components/ChannelHeaderDropdown should match snapshot with no plugin i openUp={false} /> - - void; unfavoriteChannel: (channelId: string) => void; }; type Props = { - show: boolean; + show?: boolean; channel: Channel; isFavorite: boolean; actions: Action; }; -export default class ToggleFavoriteChannel extends React.PureComponent { - static defaultProps = { - show: true, - }; - - toggleFavoriteChannel = (channelId: string) => { - const { - isFavorite, - actions: { - favoriteChannel, - unfavoriteChannel, - }, - } = this.props; +const ToggleFavoriteChannel = ({ + show = true, + isFavorite, + actions: { + favoriteChannel, + unfavoriteChannel, + }, + channel, +}: Props) => { + const intl = useIntl(); + const toggleFavoriteChannel = useCallback((channelId: string) => { return isFavorite ? unfavoriteChannel(channelId) : favoriteChannel(channelId); - }; + }, [isFavorite, favoriteChannel, unfavoriteChannel]); - handleClick = (e: React.MouseEvent): void => { + const handleClick = useCallback((e: MouseEvent): void => { e.preventDefault(); - this.toggleFavoriteChannel(this.props.channel.id); - }; + toggleFavoriteChannel(channel.id); + }, [channel.id, toggleFavoriteChannel]); - render() { - let text; - if (this.props.isFavorite) { - text = localizeMessage('channelHeader.removeFromFavorites', 'Remove from Favorites'); - } else { - text = localizeMessage('channelHeader.addToFavorites', 'Add to Favorites'); - } - return ( - - ); + let text; + if (isFavorite) { + text = intl.formatMessage({id: 'channelHeader.removeFromFavorites', defaultMessage: 'Remove from Favorites'}); + } else { + text = intl.formatMessage({id: 'channelHeader.addToFavorites', defaultMessage: 'Add to Favorites'}); } -} + return ( + + ); +}; + +export default memo(ToggleFavoriteChannel);