Skip to content

Commit

Permalink
Add broken avatar fallback
Browse files Browse the repository at this point in the history
Signed-off-by: Ajay Bura <ajbura@gmail.com>
  • Loading branch information
ajbura committed Jan 16, 2022
1 parent 62c9e27 commit f0c9a45
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 18 additions & 0 deletions public/res/svg/image-broken.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/app/atoms/avatar/Avatar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { twemojify } from '../../../util/twemojify';
import Text from '../text/Text';
import RawIcon from '../system-icons/RawIcon';

import ImageBrokenSVG from '../../../../public/res/svg/image-broken.svg';

function Avatar({
text, bgColor, iconSrc, iconColor, imageSrc, size,
}) {
Expand All @@ -19,7 +21,7 @@ function Avatar({
<div className={`avatar-container avatar-container__${size} noselect`}>
{
imageSrc !== null
? <img draggable="false" src={imageSrc} alt="avatar" />
? <img draggable="false" src={imageSrc} onError={(e) => { e.target.src = ImageBrokenSVG; }} alt="avatar" />
: (
<span
style={{ backgroundColor: iconSrc === null ? bgColor : 'transparent' }}
Expand Down

0 comments on commit f0c9a45

Please sign in to comment.