From d99cf5c0bda48c92d1327c4e3baa309992cbf8ea Mon Sep 17 00:00:00 2001 From: dougfabris Date: Thu, 28 Nov 2024 12:47:45 -0300 Subject: [PATCH] fix: review --- apps/meteor/client/providers/AvatarUrlProvider.tsx | 2 +- packages/ui-avatar/src/components/UserAvatar.tsx | 9 ++++++--- packages/ui-contexts/src/AvatarUrlContext.ts | 2 +- packages/ui-contexts/src/hooks/useUserAvatarPath.ts | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/meteor/client/providers/AvatarUrlProvider.tsx b/apps/meteor/client/providers/AvatarUrlProvider.tsx index ee23ca071ee4..056bc10e0d52 100644 --- a/apps/meteor/client/providers/AvatarUrlProvider.tsx +++ b/apps/meteor/client/providers/AvatarUrlProvider.tsx @@ -13,7 +13,7 @@ const AvatarUrlProvider = ({ children }: AvatarUrlProviderProps) => { const contextValue = useMemo(() => { function getUserPathAvatar(username: string, etag?: string): string; function getUserPathAvatar({ userId, etag }: { userId: string; etag?: string }): string; - function getUserPathAvatar({ username, etag }: { username?: string; etag?: string }): string; + function getUserPathAvatar({ username, etag }: { username: string; etag?: string }): string; function getUserPathAvatar(...args: any): string { if (typeof args[0] === 'string') { const [username, etag] = args; diff --git a/packages/ui-avatar/src/components/UserAvatar.tsx b/packages/ui-avatar/src/components/UserAvatar.tsx index ce15ff8fca09..b4f5ae85a658 100644 --- a/packages/ui-avatar/src/components/UserAvatar.tsx +++ b/packages/ui-avatar/src/components/UserAvatar.tsx @@ -13,7 +13,6 @@ type UserIdProp = { userId: string; username?: never; }; - type UserAvatarProps = Omit & { etag?: string; url?: string; @@ -27,9 +26,13 @@ const UserAvatar = ({ username, userId, etag, ...rest }: UserAvatarProps) => { const { url = getUserAvatarPath({ userId, etag }), ...props } = rest; return ; } + if (username) { + const { url = getUserAvatarPath({ username, etag }), ...props } = rest; + return ; + } - const { url = getUserAvatarPath({ username, etag }), ...props } = rest; - return ; + // TODO: We should throw an Error after fixing the issue in Composer passing the username undefined + return null; }; export default memo(UserAvatar); diff --git a/packages/ui-contexts/src/AvatarUrlContext.ts b/packages/ui-contexts/src/AvatarUrlContext.ts index 760c89bc2dc0..1f13e2764720 100644 --- a/packages/ui-contexts/src/AvatarUrlContext.ts +++ b/packages/ui-contexts/src/AvatarUrlContext.ts @@ -6,7 +6,7 @@ export type AvatarUrlContextValue = { getUserPathAvatar: { (username: string, etag?: string): string; (params: { userId: string; etag?: string }): string; - (params: { username?: string; etag?: string }): string; + (params: { username: string; etag?: string }): string; }; getRoomPathAvatar: (...args: any) => string; }; diff --git a/packages/ui-contexts/src/hooks/useUserAvatarPath.ts b/packages/ui-contexts/src/hooks/useUserAvatarPath.ts index 756f64c56591..5411bf089ee3 100644 --- a/packages/ui-contexts/src/hooks/useUserAvatarPath.ts +++ b/packages/ui-contexts/src/hooks/useUserAvatarPath.ts @@ -1,5 +1,5 @@ import { useContext } from 'react'; -import { AvatarUrlContext } from '../AvatarUrlContext'; +import { AvatarUrlContext, type AvatarUrlContextValue } from '../AvatarUrlContext'; -export const useUserAvatarPath = () => useContext(AvatarUrlContext).getUserPathAvatar; +export const useUserAvatarPath = (): AvatarUrlContextValue['getUserPathAvatar'] => useContext(AvatarUrlContext).getUserPathAvatar;