Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regression: UserAvatar should always render BaseAvatar #34061

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 3 additions & 5 deletions packages/ui-avatar/src/components/UserAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type UserIdProp = {
userId: string;
username?: never;
};

type UserAvatarProps = Omit<BaseAvatarProps, 'url' | 'title'> & {
etag?: string;
url?: string;
Expand All @@ -26,12 +27,9 @@ 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} />;
}

throw new Error('ui-avatar(UserAvatar) - Either username or userId must be provided');
const { url = getUserAvatarPath({ username, etag }), ...props } = rest;
return <BaseAvatar url={url} data-username={username} title={username} {...props} />;
};

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;
dougfabris marked this conversation as resolved.
Show resolved Hide resolved
};
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, type AvatarUrlContextValue } from '../AvatarUrlContext';
import { AvatarUrlContext } from '../AvatarUrlContext';

export const useUserAvatarPath = (): AvatarUrlContextValue['getUserPathAvatar'] => useContext(AvatarUrlContext).getUserPathAvatar;
export const useUserAvatarPath = () => useContext(AvatarUrlContext).getUserPathAvatar;
Loading