Skip to content

Commit

Permalink
fix: Add fallback if book properties not available
Browse files Browse the repository at this point in the history
  • Loading branch information
john-mantas committed Aug 10, 2018
1 parent 143fb7d commit 1937b7f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Book.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import React from 'react'

class Book extends React.Component {
render() {
let image, title, authors
this.props.book.imageLinks ? image = this.props.book.imageLinks.smallThumbnail : image = ''
this.props.book.title ? title = this.props.book.title : title = 'No title available'
this.props.book.authors ? authors = this.props.book.authors : authors = 'No authors available'

return (
<div className="book">
<div className="book-top">
<div className="book-cover" style={{ width: 128, height: 193, backgroundImage: `url(${this.props.book.imageLinks.smallThumbnail})` }}></div>
<div className="book-cover" style={{ width: 128, height: 193, backgroundImage: `url(${image})` }}></div>
<div className="book-shelf-changer">
<select>
<option value="move" disabled>Move to...</option>
Expand All @@ -16,8 +21,8 @@ class Book extends React.Component {
</select>
</div>
</div>
<div className="book-title">{this.props.book.title}</div>
<div className="book-authors">{this.props.book.authors}</div>
<div className="book-title">{title}</div>
<div className="book-authors">{authors}</div>
</div>
);
}
Expand Down

0 comments on commit 1937b7f

Please sign in to comment.