From c38ebe7ba04090f653724779d51b070ff87694c6 Mon Sep 17 00:00:00 2001 From: Heikki Hellgren Date: Tue, 26 Nov 2024 21:28:26 +0200 Subject: [PATCH] feat: add user image to user page closes #216 --- .../components/Buttons/UserFollowButton.tsx | 10 ++- .../components/TagsAndEntities/UserChip.tsx | 46 +++++++++---- plugins/qeta-react/src/hooks/index.ts | 1 + .../qeta-react/src/hooks/useEntityAuthor.ts | 66 +++++++++++-------- plugins/qeta-react/src/translation.ts | 1 + .../qeta/src/components/UserPage/UserPage.tsx | 28 +++++--- 6 files changed, 103 insertions(+), 49 deletions(-) diff --git a/plugins/qeta-react/src/components/Buttons/UserFollowButton.tsx b/plugins/qeta-react/src/components/Buttons/UserFollowButton.tsx index a1c37487..933e73ef 100644 --- a/plugins/qeta-react/src/components/Buttons/UserFollowButton.tsx +++ b/plugins/qeta-react/src/components/Buttons/UserFollowButton.tsx @@ -1,11 +1,14 @@ -import React from 'react'; +import React, { CSSProperties } from 'react'; import Visibility from '@material-ui/icons/Visibility'; import VisibilityOff from '@material-ui/icons/VisibilityOff'; import { useTranslation, useUserFollow } from '../../hooks'; import { IconButton, Tooltip } from '@material-ui/core'; -export const UserFollowButton = (props: { userRef: string }) => { - const { userRef } = props; +export const UserFollowButton = (props: { + userRef: string; + style?: CSSProperties; +}) => { + const { userRef, style } = props; const { t } = useTranslation(); const users = useUserFollow(); if (users.loading) { @@ -25,6 +28,7 @@ export const UserFollowButton = (props: { userRef: string }) => { users.followUser(userRef); } }} + style={style} > {users.isFollowingUser(userRef) ? : } diff --git a/plugins/qeta-react/src/components/TagsAndEntities/UserChip.tsx b/plugins/qeta-react/src/components/TagsAndEntities/UserChip.tsx index 1ab9cf2e..ce5b5b74 100644 --- a/plugins/qeta-react/src/components/TagsAndEntities/UserChip.tsx +++ b/plugins/qeta-react/src/components/TagsAndEntities/UserChip.tsx @@ -1,20 +1,35 @@ import { useRouteRef } from '@backstage/core-plugin-api'; import { userRouteRef } from '../../routes'; -import { useTranslation, useUserFollow } from '../../hooks'; +import { + useIdentityApi, + useTranslation, + useUserFollow, + useUserInfo, +} from '../../hooks'; import { useEntityPresentation } from '@backstage/plugin-catalog-react'; import React from 'react'; import { useNavigate } from 'react-router-dom'; -import { Button, Chip, Grid, Tooltip, Typography } from '@material-ui/core'; +import { + Avatar, + Box, + Button, + Chip, + Grid, + Tooltip, + Typography, +} from '@material-ui/core'; export const UserTooltip = (props: { entityRef: string }) => { const { entityRef } = props; const { t } = useTranslation(); - const { - primaryTitle: userName, - Icon, - secondaryTitle, - } = useEntityPresentation( - entityRef.startsWith('user:') ? entityRef : `user:${entityRef}`, + const { name, initials, user, secondaryTitle } = useUserInfo( + entityRef, + entityRef === 'anonymous', + ); + + const { value: currentUser } = useIdentityApi( + api => api.getBackstageIdentity(), + [], ); const users = useUserFollow(); @@ -22,14 +37,23 @@ export const UserTooltip = (props: { entityRef: string }) => { - {Icon ? : null} - {entityRef === 'anonymous' ? t('userLink.anonymous') : userName} + + + {initials} + + + {name} {secondaryTitle} - {!users.loading && ( + {!users.loading && currentUser?.userEntityRef !== entityRef && (