Skip to content

Commit 3d096cb

Browse files
Luteceskipjack
authored andcommitted
fix(support): default broken/missing images to webpack icon (#1846)
1 parent 03ec169 commit 3d096cb

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/components/Support/Support.jsx

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import Backers from './support-backers.json';
33
import Additional from './support-additional.js';
4+
import SmallIcon from '../../assets/icon-square-small-slack.png';
45
import './Support.scss';
56

67
const SUPPORTERS = [ ...Backers ];
@@ -100,11 +101,11 @@ export default class Support extends React.Component {
100101
title={ `$${formatMoney(supporter.totalDonations / 100)} by ${supporter.name || supporter.slug}` }
101102
target="_blank"
102103
href={ supporter.website || `https://opencollective.com/${supporter.slug}` }>
103-
{ supporter.avatar ? <img
104+
{<img
104105
className={ `support__${rank}-avatar` }
105-
src={ supporter.avatar }
106-
alt={ supporter.name || supporter.slug ? `${supporter.name || supporter.slug}'s avatar` : 'avatar' } /> :
107-
<span className={ `support__${rank}-avatar` }>{supporter.name || supporter.slug}</span> }
106+
src={ supporter.avatar || SmallIcon }
107+
alt={ supporter.name || supporter.slug ? `${supporter.name || supporter.slug}'s avatar` : 'avatar' }
108+
onError={ this._handleImgError } />}
108109
{ rank === 'backer' ? <figure className="support__outline" /> : null }
109110
</a>
110111
))
@@ -118,4 +119,14 @@ export default class Support extends React.Component {
118119
</div>
119120
);
120121
}
122+
123+
/**
124+
* Handle images that aren't found
125+
*
126+
* @param {object} e - React synthetic event
127+
*/
128+
_handleImgError(e) {
129+
const imgNode = e.target;
130+
imgNode.src = SmallIcon;
131+
}
121132
}

0 commit comments

Comments
 (0)