Skip to content

Commit 3997c6e

Browse files
Post-review adjustments
1 parent d947464 commit 3997c6e

5 files changed

Lines changed: 23 additions & 21 deletions

File tree

src/components/Avatar/Avatar.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const Avatar = ({
5353
className,
5454
FallbackIcon = IconUser,
5555
imageUrl,
56+
initials: customInitials,
5657
isOnline,
5758
size,
5859
userName,
@@ -63,17 +64,16 @@ export const Avatar = ({
6364
useEffect(() => () => setError(false), [imageUrl]);
6465

6566
const nameString = userName?.toString().trim() || '';
66-
const avatarImageAlt = nameString.trim();
6767

6868
const sizeAwareInitials = useMemo(() => {
69-
const initials = rest.initials || getInitials(nameString);
69+
const initials = customInitials || getInitials(nameString);
7070

7171
if (size === 'sm' || size === 'xs') {
7272
return initials.charAt(0);
7373
}
7474

7575
return initials;
76-
}, [nameString, size, rest.initials]);
76+
}, [nameString, size, customInitials]);
7777

7878
const showImage = typeof imageUrl === 'string' && imageUrl && !error;
7979

@@ -100,7 +100,7 @@ export const Avatar = ({
100100
)}
101101
{showImage ? (
102102
<img
103-
alt={avatarImageAlt}
103+
alt={nameString}
104104
className='str-chat__avatar-image'
105105
data-testid='avatar-img'
106106
onError={() => setError(true)}

src/components/TextareaComposer/SuggestionList/MentionItem/UserItem.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import clsx from 'clsx';
22
import React, { useMemo } from 'react';
3-
import type { UserResponse, UserSuggestion } from 'stream-chat';
3+
import type { UserSuggestion } from 'stream-chat';
44
import { Avatar as DefaultAvatar } from '../../../Avatar';
55
import { extractDisplayInfo as defaultExtractDisplayInfo } from '../../../Avatar/utils';
66
import { ListItemLayout } from '../../../ListItemLayout';
@@ -32,16 +32,15 @@ export const UserItem = ({ entity, focused, ...buttonProps }: UserItemProps) =>
3232
const hasEntity = !!Object.keys(entity).length;
3333

3434
const titleAttribute = entity.name || entity.id || '';
35-
const displayInfo = extractDisplayInfo({ user: entity });
36-
const LeadingSlot = useMemo(
37-
() =>
38-
function UserItemAvatar() {
39-
// Decorative: the option's accessible name already carries the user's name (title +
40-
// tokenized display name), so the avatar's fallback initials/role would only add noise.
41-
return <Avatar {...displayInfo} aria-hidden size='md' />;
42-
},
43-
[Avatar, displayInfo],
44-
);
35+
const LeadingSlot = useMemo(() => {
36+
const displayInfo = extractDisplayInfo({ user: entity });
37+
38+
return function UserItemAvatar() {
39+
// Decorative: the option's accessible name already carries the user's name (title +
40+
// tokenized display name), so the avatar's fallback initials/role would only add noise.
41+
return <Avatar {...displayInfo} aria-hidden size='md' />;
42+
};
43+
}, [Avatar, entity, extractDisplayInfo]);
4544

4645
if (!hasEntity) return null;
4746

src/plugins/ChannelDetail/Views/ChannelMembersView/ChannelMembersAddView.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,15 @@ const ChannelMembersAddViewItem = ({
6565
const { Avatar = DefaultAvatar, extractDisplayInfo = defaultExtractDisplayInfo } =
6666
useComponentContext();
6767
const displayName = getUserDisplayName(user);
68-
const displayInfo = extractDisplayInfo({ user });
6968

7069
const LeadingSlot = useMemo(
7170
() =>
7271
function MemberAvatar() {
72+
const displayInfo = extractDisplayInfo({ user });
73+
7374
return <Avatar {...displayInfo} isOnline={user.online} size='md' />;
7475
},
75-
[Avatar, displayInfo, user.online],
76+
[Avatar, extractDisplayInfo, user],
7677
);
7778

7879
const SelectableTrailingSlot = useMemo(

src/plugins/ChannelDetail/Views/ChannelMembersView/ChannelMembersBrowseView.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@ const ChannelMembersBrowseViewItem = ({
6262
const user = member.user;
6363
const displayName = getMemberDisplayName(member);
6464
const roleTranslation = getMemberRoleTranslation(member, t);
65-
const displayInfo = extractDisplayInfo({ user: user ?? undefined });
6665

6766
const LeadingSlot = useMemo(
6867
() =>
6968
function MemberAvatar() {
69+
const displayInfo = extractDisplayInfo({ user: user ?? undefined });
70+
7071
return <Avatar {...displayInfo} isOnline={user?.online} size='md' />;
7172
},
72-
[Avatar, displayInfo, user],
73+
[Avatar, extractDisplayInfo, user],
7374
);
7475

7576
const TrailingSlot = useMemo(

src/plugins/ChannelDetail/Views/PinnedMessagesView/PinnedMessagesView.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,15 @@ const PinnedMessagesViewItem = ({
8787
const { Avatar = DefaultAvatar, extractDisplayInfo = defaultExtractDisplayInfo } =
8888
useComponentContext();
8989
const displayName = getUserDisplayName(message.user ?? undefined);
90-
const displayInfo = extractDisplayInfo({ user: message.user ?? undefined });
9190

9291
const LeadingSlot = useMemo(
9392
() =>
9493
function MessageAuthorAvatar() {
94+
const displayInfo = extractDisplayInfo({ user: message.user ?? undefined });
95+
9596
return <Avatar {...displayInfo} size='md' />;
9697
},
97-
[Avatar, displayInfo],
98+
[Avatar, extractDisplayInfo, message.user],
9899
);
99100

100101
const TrailingSlot = useMemo(

0 commit comments

Comments
 (0)