From 585d7bc1e1eb6920e44d49aff771d77a0fffe1c1 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Wed, 8 Nov 2017 10:19:27 -0500 Subject: [PATCH] Changed PostProfilePicture to be a PureComponent (#1105) * Changed PostProfilePicture to be a PureComponent * Updating style --- .../post_profile_picture.js | 101 +++++++++--------- 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/app/components/post_profile_picture/post_profile_picture.js b/app/components/post_profile_picture/post_profile_picture.js index 2b3162250..e2fb4bfa5 100644 --- a/app/components/post_profile_picture/post_profile_picture.js +++ b/app/components/post_profile_picture/post_profile_picture.js @@ -1,7 +1,7 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import React from 'react'; +import React, {PureComponent} from 'react'; import PropTypes from 'prop-types'; import {Image, TouchableOpacity, View} from 'react-native'; @@ -12,29 +12,47 @@ import webhookIcon from 'assets/images/icons/webhook.jpg'; const PROFILE_PICTURE_SIZE = 32; -function PostProfilePicture(props) { - const { - enablePostIconOverride, - fromWebHook, - isSystemMessage, - onViewUserProfile, - overrideIconUrl, - theme, - userId - } = props; - if (isSystemMessage) { - return ( - - - - ); - } else if (fromWebHook) { - if (enablePostIconOverride) { +export default class PostProfilePicture extends PureComponent { + static propTypes = { + enablePostIconOverride: PropTypes.bool, + fromWebHook: PropTypes.bool, + isSystemMessage: PropTypes.bool, + overrideIconUrl: PropTypes.string, + onViewUserProfile: PropTypes.func, + theme: PropTypes.object, + userId: PropTypes.string + }; + + static defaultProps = { + onViewUserProfile: emptyFunction + }; + + render() { + const { + enablePostIconOverride, + fromWebHook, + isSystemMessage, + onViewUserProfile, + overrideIconUrl, + theme, + userId + } = this.props; + + if (isSystemMessage) { + return ( + + + + ); + } + + if (fromWebHook && enablePostIconOverride) { const icon = overrideIconUrl ? {uri: overrideIconUrl} : webhookIcon; + return ( ); + + if (!fromWebHook) { + component = ( + + {component} + + ); + } + + return component; } - - return ( - - - - ); } - -PostProfilePicture.propTypes = { - enablePostIconOverride: PropTypes.bool, - fromWebHook: PropTypes.bool, - isSystemMessage: PropTypes.bool, - overrideIconUrl: PropTypes.string, - onViewUserProfile: PropTypes.func, - theme: PropTypes.object, - userId: PropTypes.string -}; - -PostProfilePicture.defaultProps = { - onViewUserProfile: emptyFunction -}; - -export default PostProfilePicture;