Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add robot placeholder image #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
.env.development.local
.env.test.local
.env.production.local
.vscode

npm-debug.log*
yarn-debug.log*
Expand Down
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 33 additions & 10 deletions src/components/Card.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
import React from 'react';
import placeholder from '../images/placeholder.jpg';

const Card = ({ name, email, id }) => {
return (
<div className='tc grow bg-light-green br3 pa3 ma2 dib bw2 shadow-5'>
<img alt='robots' src={`https://robohash.org/${id}?size=200x200`} />
<div>
<h2>{name}</h2>
<p>{email}</p>
class Card extends React.Component {
constructor(props) {
super(props);
this.state = {
hasImageLoaded: false
};
}

setImageLoaded = () => {
this.setState({ hasImageLoaded: true });
}

render() {
const { name, email, id } = this.props;
const robotImageUrl = `https://robohash.org/${id}?size=200x200`;

const { hasImageLoaded } = this.state;

return (
<div className="tc bg-light-green dib br3 pa3 ma2 grow bw2 shadow-5">
<img
src={hasImageLoaded ? robotImageUrl : placeholder}
alt="robots"
onLoad={this.setImageLoaded}
/>
<div>
<h2>{name}</h2>
<p>{email}</p>
</div>
</div>
</div>
);
);
}
}

export default Card;
export default Card;
Binary file added src/images/placeholder.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.