From e59be1982915dfe3854786e5f77cfd3ac4b8a4e3 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 11 Apr 2024 11:38:54 +0700 Subject: [PATCH] Refactor layout of WorkspaceListRow --- src/pages/workspace/WorkspacesListRow.tsx | 197 ++++++++++------------ 1 file changed, 93 insertions(+), 104 deletions(-) diff --git a/src/pages/workspace/WorkspacesListRow.tsx b/src/pages/workspace/WorkspacesListRow.tsx index 54717b032ebe..1a6ef8c20577 100644 --- a/src/pages/workspace/WorkspacesListRow.tsx +++ b/src/pages/workspace/WorkspacesListRow.tsx @@ -21,6 +21,7 @@ import type {AnchorPosition} from '@styles/index'; import variables from '@styles/variables'; import CONST from '@src/CONST'; import type IconAsset from '@src/types/utils/IconAsset'; +import useWindowDimensions from '@hooks/useWindowDimensions'; type WorkspacesListRowProps = WithCurrentUserPersonalDetailsProps & { /** Name of the workspace */ @@ -108,6 +109,7 @@ function WorkspacesListRow({ const {translate} = useLocalize(); const [threeDotsMenuPosition, setThreeDotsMenuPosition] = useState({horizontal: 0, vertical: 0}); const threeDotsMenuContainerRef = useRef(null); + const {isSmallScreenWidth} = useWindowDimensions(); const ownerDetails = ownerAccountID && PersonalDetailsUtils.getPersonalDetailsByIDs([ownerAccountID], currentUserPersonalDetails.accountID)[0]; @@ -136,124 +138,111 @@ function WorkspacesListRow({ const isDeleted = style && Array.isArray(style) ? style.includes(styles.offlineFeedback.deleted) : false; return ( - - - - - {title} - - {isNarrow && - (!isJoinRequestPending ? ( + + + + + + {title} + + + + {!!ownerDetails && ( <> - - + + + {PersonalDetailsUtils.getDisplayNameOrDefault(ownerDetails)} + + + {ownerDetails.login} + + - ) : ( + )} + + + + + + {userFriendlyWorkspaceType} + + + {translate('workspace.common.plan')} + + + + + + {isJoinRequestPending && ( + - ))} - - - {!!ownerDetails && ( + + )} + {!isJoinRequestPending && ( <> - - - - {PersonalDetailsUtils.getDisplayNameOrDefault(ownerDetails)} - - - {ownerDetails.login} - + + + + + { + if (isSmallScreenWidth) { + return; + } + threeDotsMenuContainerRef.current?.measureInWindow((x, y, width, height) => { + setThreeDotsMenuPosition({ + horizontal: x + width, + vertical: y + height, + }); + }); + }} + menuItems={menuItems} + anchorPosition={threeDotsMenuPosition} + anchorAlignment={{horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT, vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP}} + shouldOverlay + disabled={shouldDisableThreeDotsMenu} + /> )} - - - - - {userFriendlyWorkspaceType} - - - {translate('workspace.common.plan')} - - - - {isJoinRequestPending && !isNarrow && ( - - - - )} - - {isWide && !isJoinRequestPending && ( - <> - - - - - { - threeDotsMenuContainerRef.current?.measureInWindow((x, y, width, height) => { - setThreeDotsMenuPosition({ - horizontal: x + width, - vertical: y + height, - }); - }); - }} - menuItems={menuItems} - anchorPosition={threeDotsMenuPosition} - anchorAlignment={{horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT, vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP}} - iconStyles={[styles.mr2]} - shouldOverlay - disabled={shouldDisableThreeDotsMenu} - /> - - - )} ); }