daily pastebin goal
19%
SHARE
TWEET

listBooks.js

a guest May 22nd, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react'
  2. import * as BooksAPI from '../BooksAPI'
  3. import { Link } from 'react-router-dom'
  4. import BookShelf from './bookShelf'
  5. import '../App.css'
  6.  
  7. class ListBooks extends Component {
  8.   constructor() {
  9.     super();
  10.     this.state = {
  11.       homeLink: "Changed Link",
  12.       bookList: []
  13.     };
  14.  
  15.     this.updateBookStatus = this.updateBookStatus.bind(this);
  16.   }
  17.  
  18.   componentDidMount() {
  19.     BooksAPI.getAll().then(res => {
  20.       this.setState({
  21.         bookList: res
  22.       })
  23.     });
  24.   }
  25.  
  26.   updateBookStatus(book, newShelf) {
  27.     BooksAPI.update(book, newShelf).then(res => {
  28.       BooksAPI.getAll().then(res => {
  29.         this.setState({
  30.             bookList: res
  31.         })
  32.       });
  33.     });
  34.     }
  35.  
  36.   onChangeLink() {
  37.     this.props.changeLink(this.state.homeLink);
  38.   }
  39.  
  40.   render() {
  41.     const shelves = {
  42.       currentlyReading: ['Currently Reading', 'currentlyReading'],
  43.       wantToRead: ['Want to Read', 'wantToRead'],
  44.       read: ['Read', 'read']
  45.     }
  46.  
  47.  
  48.     return (
  49.       <div className="list-books">
  50.           <div className="list-books-title">
  51.               <h1>MyReads</h1>
  52.           </div>
  53.           <div className="list-books-content">
  54.             { Object.keys(shelves).map((shelf) =>
  55.               <BookShelf key={shelf}
  56.                 updateBook={this.updateBookStatus}
  57.                 books={this.state.bookList.filter(book => book.shelf === shelves[shelf][1])}
  58.                 title={shelves[shelf][0]}/>
  59.               )}
  60.           </div>
  61.           <div className="open-search">
  62.             <Link
  63.               to='/search'
  64.             >Add a book</Link>
  65.           </div>
  66.       </div>
  67.     )
  68.   }
  69. }
  70.  
  71. export default ListBooks;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top