Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris committed Nov 28, 2024
1 parent 41445d2 commit d99cf5c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/client/providers/AvatarUrlProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions packages/ui-avatar/src/components/UserAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type UserIdProp = {
userId: string;
username?: never;
};

type UserAvatarProps = Omit<BaseAvatarProps, 'url' | 'title'> & {
etag?: string;
url?: string;
Expand All @@ -27,9 +26,13 @@ const UserAvatar = ({ username, userId, etag, ...rest }: UserAvatarProps) => {
const { url = getUserAvatarPath({ userId, etag }), ...props } = rest;
return <BaseAvatar url={url} {...props} />;
}
if (username) {
const { url = getUserAvatarPath({ username, etag }), ...props } = rest;
return <BaseAvatar url={url} data-username={username} title={username} {...props} />;
}

const { url = getUserAvatarPath({ username, etag }), ...props } = rest;
return <BaseAvatar url={url} data-username={username} title={username} {...props} />;
// TODO: We should throw an Error after fixing the issue in Composer passing the username undefined
return null;
};

export default memo(UserAvatar);
2 changes: 1 addition & 1 deletion packages/ui-contexts/src/AvatarUrlContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
4 changes: 2 additions & 2 deletions packages/ui-contexts/src/hooks/useUserAvatarPath.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit d99cf5c

Please sign in to comment.