Handle error when loading avatar, show default

This commit is contained in:
Tom Moor
2017-11-11 12:22:23 -08:00
parent f34b32b2a3
commit 6b7e09f063
3 changed files with 36 additions and 13 deletions

View File

@@ -1,10 +1,36 @@
// @flow
import React, { Component } from 'react';
import styled from 'styled-components';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
import { color } from 'shared/styles/constants';
import placeholder from './placeholder.png';
const Avatar = styled.img`
@observer
class Avatar extends Component {
@observable error: boolean;
handleError = () => {
this.error = true;
};
render() {
return (
<CircleImg
{...this.props}
onError={this.handleError}
src={this.error ? placeholder : this.props.src}
/>
);
}
}
const CircleImg = styled.img`
width: 24px;
height: 24px;
border-radius: 50%;
border: 2px solid ${color.white};
flex-shrink: 0;
`;
export default Avatar;

Binary file not shown.

After

Width:  |  Height:  |  Size: 976 B