Skip to content

Commit

Permalink
AvatarPreview: Use avatarPath directly if provided
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Nonnenberg <scott@signal.org>
  • Loading branch information
automated-signal and scottnonnenberg-signal committed Sep 27, 2021
1 parent 60b6285 commit 5a98304
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions ts/components/AvatarPreview.tsx
Expand Up @@ -50,8 +50,14 @@ export const AvatarPreview = ({

const [avatarPreview, setAvatarPreview] = useState<ArrayBuffer | undefined>();

// Loads the initial avatarPath if one is provided.
// Loads the initial avatarPath if one is provided, but only if we're in editable mode.
// If we're not editable, we assume that we either have an avatarPath or we show a
// default avatar.
useEffect(() => {
if (!isEditable) {
return;
}

const startingAvatarPath = startingAvatarPathRef.current;
if (!startingAvatarPath) {
return noop;
Expand Down Expand Up @@ -84,7 +90,7 @@ export const AvatarPreview = ({
return () => {
shouldCancel = true;
};
}, [onAvatarLoaded]);
}, [onAvatarLoaded, isEditable]);

// Ensures that when avatarValue changes we generate new URLs
useEffect(() => {
Expand Down Expand Up @@ -115,7 +121,7 @@ export const AvatarPreview = ({
let imageStatus: ImageStatus;
if (avatarValue && !objectUrl) {
imageStatus = ImageStatus.Loading;
} else if (objectUrl) {
} else if (objectUrl || avatarPath) {
imageStatus = ImageStatus.HasImage;
} else {
imageStatus = ImageStatus.Nothing;
Expand All @@ -131,7 +137,7 @@ export const AvatarPreview = ({
componentStyle.cursor = 'pointer';
}

if (!avatarPreview) {
if (imageStatus === ImageStatus.Nothing) {
return (
<div className="AvatarPreview">
<div
Expand Down Expand Up @@ -161,7 +167,7 @@ export const AvatarPreview = ({
imageStatus === ImageStatus.HasImage
? {
...componentStyle,
backgroundImage: `url(${objectUrl})`,
backgroundImage: `url('${objectUrl || avatarPath}')`,
}
: componentStyle
}
Expand Down

0 comments on commit 5a98304

Please sign in to comment.