diff --git a/src/App.js b/src/App.js index 4f2e5b3..4646dca 100644 --- a/src/App.js +++ b/src/App.js @@ -9,16 +9,19 @@ class BooksApp extends React.Component { state = { books: [] } - componentDidMount() { + updateBooks = () => ( BooksAPI.getAll().then(books => { this.setState({ books }) - }) + }) + ) + componentDidMount() { + this.updateBooks() } render() { return (
- - ()} /> + ()} /> + ()} />
) } diff --git a/src/Book.js b/src/Book.js index a5b25ab..3e800f1 100644 --- a/src/Book.js +++ b/src/Book.js @@ -1,6 +1,27 @@ import React from 'react' +import * as BooksAPI from './BooksAPI' class Book extends React.Component { + state = { + shelf: 'none' + } + updateShelf(value) { + this.setState({ + shelf: value + }) + BooksAPI.update(this.props.book, value).then((response) => ( + this.props.updateBooks() + )) + } + componentDidMount() { + (this.props.book.shelf) + ? (this.updateShelf(this.props.book.shelf)) + : (this.props.parentState.books + .filter(f => (f.id === this.props.book.id)) + .map(m => (this.setState({ shelf: m.shelf })) + ) + ) + } render() { let image, title, authors this.props.book.imageLinks ? image = this.props.book.imageLinks.smallThumbnail : image = '' @@ -8,11 +29,13 @@ class Book extends React.Component { this.props.book.authors ? authors = this.props.book.authors : authors = 'No authors available' return ( -
-
-
+
+
+
- ( + this.updateShelf(e.target.value) + )}> @@ -20,10 +43,10 @@ class Book extends React.Component {
+
+
{title}
+
{authors}
-
{title}
-
{authors}
-
); } } diff --git a/src/Bookshelf.js b/src/Bookshelf.js index d38723d..df570c2 100644 --- a/src/Bookshelf.js +++ b/src/Bookshelf.js @@ -8,7 +8,7 @@ class Bookshelf extends React.Component {

{this.props.title}

    - {this.props.shelf.map((books) => (
  1. ))} + {this.props.shelf.map((books) => (
  2. ))}
diff --git a/src/list-books.js b/src/list-books.js index a1bc9b0..38ec0a1 100644 --- a/src/list-books.js +++ b/src/list-books.js @@ -15,9 +15,9 @@ class ListBooks extends React.Component {
- - - + + +
diff --git a/src/search.js b/src/search.js index c7ead1d..dbec430 100644 --- a/src/search.js +++ b/src/search.js @@ -13,8 +13,6 @@ class SearchPage extends React.Component { BooksAPI.search(query).then((response) => { if (response) { this.setState({ searchResults: response }) - console.log(`search query: ${this.state.query}`) - console.log(`search response: ${this.state.searchResults}`) } else { this.setState({ searchResults: [] }) } @@ -38,8 +36,8 @@ class SearchPage extends React.Component {
    {(this.state.searchResults.length > 0) && ( - this.state.searchResults.map(books => (
  1. )) - )} + this.state.searchResults.map(books => (
  2. )) + )}