From 2f68defa4ba5df626ed7770dd84c4f8d07a0c047 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Mon, 27 Sep 2021 12:16:42 -0700 Subject: [PATCH] AvatarPreview: Use avatarPath directly if provided --- ts/components/AvatarPreview.tsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ts/components/AvatarPreview.tsx b/ts/components/AvatarPreview.tsx index efe9c48f7b..02c3e17d68 100644 --- a/ts/components/AvatarPreview.tsx +++ b/ts/components/AvatarPreview.tsx @@ -50,8 +50,14 @@ export const AvatarPreview = ({ const [avatarPreview, setAvatarPreview] = useState(); - // 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; @@ -84,7 +90,7 @@ export const AvatarPreview = ({ return () => { shouldCancel = true; }; - }, [onAvatarLoaded]); + }, [onAvatarLoaded, isEditable]); // Ensures that when avatarValue changes we generate new URLs useEffect(() => { @@ -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; @@ -131,7 +137,7 @@ export const AvatarPreview = ({ componentStyle.cursor = 'pointer'; } - if (!avatarPreview) { + if (imageStatus === ImageStatus.Nothing) { return (