Skip to content

Commit 3b91f6d

Browse files
authored
Fix gradient showing instead of placeholder when Avatar URL loading fails
1 parent b4b3210 commit 3b91f6d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

ts/components/Avatar.stories.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ const createProps = (overrideProps: Partial<Props> = {}): Props => ({
6464
blur: overrideProps.blur,
6565
color: overrideProps.color || AvatarColors[0],
6666
conversationType: overrideProps.conversationType || 'direct',
67-
hasAvatar: Boolean(overrideProps.hasAvatar),
67+
hasAvatar:
68+
Boolean(overrideProps.hasAvatar) ||
69+
(overrideProps.avatarUrl != null && overrideProps.avatarUrl.length > 0),
6870
i18n,
6971
loading: Boolean(overrideProps.loading),
7072
noteToSelf: Boolean(overrideProps.noteToSelf),

ts/components/Avatar.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ export function Avatar({
144144
}, [avatarUrl]);
145145

146146
const initials = getInitials(title);
147-
const hasImage = !noteToSelf && avatarUrl && !imageBroken;
147+
const hasLocalImage = !noteToSelf && avatarUrl && avatarUrl.length > 0;
148+
const hasValidImage = hasLocalImage && !imageBroken;
148149
const shouldUseInitials =
149-
!hasImage &&
150+
!hasValidImage &&
150151
conversationType === 'direct' &&
151152
Boolean(initials) &&
152153
title !== i18n('icu:unknownContact');
@@ -163,7 +164,7 @@ export function Avatar({
163164
/>
164165
</div>
165166
);
166-
} else if (hasImage) {
167+
} else if (hasValidImage) {
167168
assertDev(avatarUrl, 'avatarUrl should be defined here');
168169

169170
assertDev(
@@ -207,7 +208,7 @@ export function Avatar({
207208
)}
208209
/>
209210
);
210-
} else if (hasAvatar && !hasImage) {
211+
} else if (hasAvatar && !hasLocalImage) {
211212
contentsChildren = (
212213
<>
213214
<div

0 commit comments

Comments
 (0)