From 2c4558091806e831b840473fdf18f91fe72aa0a6 Mon Sep 17 00:00:00 2001 From: SP Singh <19812199+spcheema@users.noreply.github.com> Date: Fri, 11 Aug 2023 22:59:47 +1000 Subject: [PATCH 1/7] Enable avatar preview for workspace & thread replies --- src/components/AttachmentModal.js | 5 ++ .../Attachments/AttachmentView/index.js | 12 +++- src/components/RoomHeaderAvatars.js | 69 ++++++++++++++----- 3 files changed, 68 insertions(+), 18 deletions(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index 665123852b77..bbfb21abb334 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -71,6 +71,9 @@ const propTypes = { ...withLocalizePropTypes, ...windowDimensionsPropTypes, + + /** Denotes whether it is an avatar or a workspace avatar */ + isWorkspaceAvatar: PropTypes.bool, }; const defaultProps = { @@ -86,6 +89,7 @@ const defaultProps = { onModalShow: () => {}, onModalHide: () => {}, onCarouselAttachmentChange: () => {}, + isWorkspaceAvatar: false, }; function AttachmentModal(props) { @@ -345,6 +349,7 @@ function AttachmentModal(props) { isAuthTokenRequired={isAuthTokenRequired} file={file} onToggleKeyboard={updateConfirmButtonVisibility} + isWorkspaceAvatar={props.isWorkspaceAvatar} /> ) )} diff --git a/src/components/Attachments/AttachmentView/index.js b/src/components/Attachments/AttachmentView/index.js index 3ad643d34bcd..80871894316f 100755 --- a/src/components/Attachments/AttachmentView/index.js +++ b/src/components/Attachments/AttachmentView/index.js @@ -15,7 +15,7 @@ import variables from '../../../styles/variables'; import AttachmentViewImage from './AttachmentViewImage'; import AttachmentViewPdf from './AttachmentViewPdf'; import addEncryptedAuthTokenToURL from '../../../libs/addEncryptedAuthTokenToURL'; - +import * as StyleUtils from '../../../styles/StyleUtils'; import {attachmentViewPropTypes, attachmentViewDefaultProps} from './propTypes'; const propTypes = { @@ -34,6 +34,9 @@ const propTypes = { /** Extra styles to pass to View wrapper */ // eslint-disable-next-line react/forbid-prop-types containerStyles: PropTypes.arrayOf(PropTypes.object), + + /** Denotes whether it is an avatar or a workspace avatar */ + isWorkspaceAvatar: PropTypes.bool, }; const defaultProps = { @@ -42,6 +45,7 @@ const defaultProps = { shouldShowLoadingSpinnerIcon: false, onToggleKeyboard: () => {}, containerStyles: [], + isWorkspaceAvatar: false, }; function AttachmentView({ @@ -57,16 +61,22 @@ function AttachmentView({ onToggleKeyboard, translate, isFocused, + isWorkspaceAvatar, }) { const [loadComplete, setLoadComplete] = useState(false); // Handles case where source is a component (ex: SVG) if (_.isFunction(source)) { + const iconFillColor = isWorkspaceAvatar ? StyleUtils.getDefaultWorkspaceAvatarColor(file.name).fill : ''; + const additionalStyles = isWorkspaceAvatar ? [StyleUtils.getDefaultWorkspaceAvatarColor(file.name)] : []; + return ( ); } diff --git a/src/components/RoomHeaderAvatars.js b/src/components/RoomHeaderAvatars.js index 6f78e6ace66d..b991bd151305 100644 --- a/src/components/RoomHeaderAvatars.js +++ b/src/components/RoomHeaderAvatars.js @@ -9,6 +9,9 @@ import Avatar from './Avatar'; import themeColors from '../styles/themes/default'; import * as StyleUtils from '../styles/StyleUtils'; import avatarPropTypes from './avatarPropTypes'; +import PressableWithoutFocus from './Pressable/PressableWithoutFocus'; +import * as UserUtils from '../libs/UserUtils'; +import AttachmentModal from './AttachmentModal'; const propTypes = { icons: PropTypes.arrayOf(avatarPropTypes), @@ -25,14 +28,30 @@ function RoomHeaderAvatars(props) { if (props.icons.length === 1) { return ( - + + {({show}) => ( + + + + )} + ); } @@ -45,21 +64,37 @@ function RoomHeaderAvatars(props) { StyleUtils.getAvatarStyle(CONST.AVATAR_SIZE.LARGE_BORDERED), ]; return ( - + {_.map(iconsToDisplay, (icon, index) => ( - + + {({show}) => ( + + + + )} + {index === CONST.REPORT.MAX_PREVIEW_AVATARS - 1 && props.icons.length - CONST.REPORT.MAX_PREVIEW_AVATARS !== 0 && ( <> Date: Sat, 12 Aug 2023 00:08:48 +1000 Subject: [PATCH 2/7] Update props docs --- src/components/AttachmentModal.js | 2 +- src/components/Attachments/AttachmentView/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index bbfb21abb334..46d693a507dd 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -72,7 +72,7 @@ const propTypes = { ...windowDimensionsPropTypes, - /** Denotes whether it is an avatar or a workspace avatar */ + /** Denotes whether it is a workspace avatar or not */ isWorkspaceAvatar: PropTypes.bool, }; diff --git a/src/components/Attachments/AttachmentView/index.js b/src/components/Attachments/AttachmentView/index.js index 80871894316f..b2a8dc248e6f 100755 --- a/src/components/Attachments/AttachmentView/index.js +++ b/src/components/Attachments/AttachmentView/index.js @@ -35,7 +35,7 @@ const propTypes = { // eslint-disable-next-line react/forbid-prop-types containerStyles: PropTypes.arrayOf(PropTypes.object), - /** Denotes whether it is an avatar or a workspace avatar */ + /** Denotes whether it is a workspace avatar or not */ isWorkspaceAvatar: PropTypes.bool, }; From ffcf5752898b7997d7e72c008a6079a8df7489d6 Mon Sep 17 00:00:00 2001 From: SP Singh <19812199+spcheema@users.noreply.github.com> Date: Tue, 15 Aug 2023 19:25:12 +1000 Subject: [PATCH 3/7] Avoid duplicate func call --- src/components/Attachments/AttachmentView/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/Attachments/AttachmentView/index.js b/src/components/Attachments/AttachmentView/index.js index b2a8dc248e6f..00674eca6331 100755 --- a/src/components/Attachments/AttachmentView/index.js +++ b/src/components/Attachments/AttachmentView/index.js @@ -67,8 +67,9 @@ function AttachmentView({ // Handles case where source is a component (ex: SVG) if (_.isFunction(source)) { - const iconFillColor = isWorkspaceAvatar ? StyleUtils.getDefaultWorkspaceAvatarColor(file.name).fill : ''; - const additionalStyles = isWorkspaceAvatar ? [StyleUtils.getDefaultWorkspaceAvatarColor(file.name)] : []; + const defaultWorkspaceAvatarColor = StyleUtils.getDefaultWorkspaceAvatarColor(file.name); + const iconFillColor = isWorkspaceAvatar ? defaultWorkspaceAvatarColor.fill : ''; + const additionalStyles = isWorkspaceAvatar ? [defaultWorkspaceAvatarColor] : []; return ( Date: Tue, 15 Aug 2023 19:27:29 +1000 Subject: [PATCH 4/7] Refactor & cleanup --- src/components/Attachments/AttachmentView/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/Attachments/AttachmentView/index.js b/src/components/Attachments/AttachmentView/index.js index 00674eca6331..47353d915060 100755 --- a/src/components/Attachments/AttachmentView/index.js +++ b/src/components/Attachments/AttachmentView/index.js @@ -67,9 +67,13 @@ function AttachmentView({ // Handles case where source is a component (ex: SVG) if (_.isFunction(source)) { - const defaultWorkspaceAvatarColor = StyleUtils.getDefaultWorkspaceAvatarColor(file.name); - const iconFillColor = isWorkspaceAvatar ? defaultWorkspaceAvatarColor.fill : ''; - const additionalStyles = isWorkspaceAvatar ? [defaultWorkspaceAvatarColor] : []; + let iconFillColor = ''; + let additionalStyles = []; + if (isWorkspaceAvatar) { + const defaultWorkspaceAvatarColor = StyleUtils.getDefaultWorkspaceAvatarColor(file.name); + iconFillColor = defaultWorkspaceAvatarColor.fill; + additionalStyles = [defaultWorkspaceAvatarColor]; + } return ( Date: Tue, 15 Aug 2023 19:34:00 +1000 Subject: [PATCH 5/7] Update src/components/RoomHeaderAvatars.js Co-authored-by: Aimane Chnaif <96077027+aimane-chnaif@users.noreply.github.com> --- src/components/RoomHeaderAvatars.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/RoomHeaderAvatars.js b/src/components/RoomHeaderAvatars.js index b991bd151305..e24d31b9b5a1 100644 --- a/src/components/RoomHeaderAvatars.js +++ b/src/components/RoomHeaderAvatars.js @@ -38,7 +38,7 @@ function RoomHeaderAvatars(props) { {({show}) => ( Date: Tue, 15 Aug 2023 19:35:36 +1000 Subject: [PATCH 6/7] Replace static string with const --- src/components/RoomHeaderAvatars.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/RoomHeaderAvatars.js b/src/components/RoomHeaderAvatars.js index e24d31b9b5a1..3d803e6761a2 100644 --- a/src/components/RoomHeaderAvatars.js +++ b/src/components/RoomHeaderAvatars.js @@ -81,7 +81,7 @@ function RoomHeaderAvatars(props) { {({show}) => ( Date: Tue, 15 Aug 2023 20:35:07 +1000 Subject: [PATCH 7/7] Fix avatar hover issue in the case of multiple avatars --- src/components/RoomHeaderAvatars.js | 3 +++ src/styles/styles.js | 1 - src/styles/utilities/spacing.js | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/RoomHeaderAvatars.js b/src/components/RoomHeaderAvatars.js index 3d803e6761a2..af594dc2415a 100644 --- a/src/components/RoomHeaderAvatars.js +++ b/src/components/RoomHeaderAvatars.js @@ -37,6 +37,7 @@ function RoomHeaderAvatars(props) { > {({show}) => ( {({show}) => (