diff --git a/src/.DS_Store b/src/.DS_Store
old mode 100644
new mode 100755
diff --git a/src/App.css b/src/App.css
old mode 100644
new mode 100755
diff --git a/src/App.js b/src/App.js
old mode 100644
new mode 100755
index 6f01688f..fe069370
--- a/src/App.js
+++ b/src/App.js
@@ -6,41 +6,64 @@ import Search from './Search'
import './App.css'
class BooksApp extends Component {
+
state = {
book : [],
+ sbook : []
}
+
componentDidMount(){
- this.Booksload()
+ this.Booksload()
}
Booksload = () =>{
BooksAPI.getAll().then((book)=>{
this.setState({ book })
- console.log(book);
+ // console.log(book);
})
}
- changeShelf = (bookchange, shelf) =>{
- BooksAPI.update(bookchange, shelf)
- .then (()=> this.Booksload())
+ changeShelf = (bookchange, shelf) => {
+ BooksAPI.update(bookchange, shelf)
+ .then(() => this.Booksload());
+ // update books in search
+ this.setState(state => ({
+ sbook: state.sbook.map(b => {
+ if (b.id === bookchange.id) {
+ b.shelf = shelf;
+ }
+ return b;
+ })
+ }))
+ }
+
+ BookSearch = query => {
+ BooksAPI.search(query).then(sbook => {
+ this.setState(state => ({
+ sbook: sbook.map(b => {
+ const bookInShelf = state.book.find(bis => bis.id === b.id);
+ if (bookInShelf) b.shelf = bookInShelf.shelf;
+ return b;
+ })
+ }))
+ })
+ }
- }
render() {
return (
(
{
- this.changeShelf(book, shelf)
- }}
+ onChange = {this.changeShelf}
+
/>
)}/>
(
{
- this.changeShelf(book, shelf)
- }}
+ BookSearch = {this.BookSearch}
+ book = {this.state.sbook}
+ onChange = {this.changeShelf}
/>
)}/>
diff --git a/src/App.test.js b/src/App.test.js
old mode 100644
new mode 100755
diff --git a/src/Book.js b/src/Book.js
new file mode 100644
index 00000000..d91e32e6
--- /dev/null
+++ b/src/Book.js
@@ -0,0 +1,29 @@
+import React from 'react';
+
+
+const Book = (prop) => {
+ const {shelf, imageLinks, title, authors} = prop.book
+
+ return (
+
+
+
+
+
+
+
+
+
{title}
+
{authors}
+
+
+ )
+}
+
+export default Book;
diff --git a/src/BooksAPI.js b/src/BooksAPI.js
old mode 100644
new mode 100755
diff --git a/src/Getbook.js b/src/Getbook.js
old mode 100644
new mode 100755
index e7dd07e0..305d1d9c
--- a/src/Getbook.js
+++ b/src/Getbook.js
@@ -1,35 +1,19 @@
import React, { Component } from 'react';
import { Link } from 'react-router-dom'
-// import serialzeForm from 'form-serialize'
+import Book from './Book'
class Getbook extends Component {
- handleChange = (book, shelf) => {
- this.props.onUpdateBook(book, shelf)
- }
renderUserMessage(ready){
return this.props.book.map((gbook) => {
// console.log(bookks)
if (gbook.shelf === ready) {
return (
-
-
-
-
-
-
-
-
-
{gbook.title}
-
{gbook.authors}
-
-
+
);
}
@@ -77,7 +61,6 @@ class Getbook extends Component {
-
)
}
}
diff --git a/src/Search.js b/src/Search.js
old mode 100644
new mode 100755
index 256fc0fb..c25ff5de
--- a/src/Search.js
+++ b/src/Search.js
@@ -1,26 +1,15 @@
import React, { Component } from 'react';
import { Link } from 'react-router-dom'
-import * as BooksAPI from './BooksAPI'
+import Book from './Book'
class Search extends Component {
-
state = {
query: '',
- sbook: []
}
updateQuery = (query) => {
this.setState({ query: query.trim() })
- BooksAPI.search(query).then((sbook)=>{
- this.setState({ sbook })
- // console.log(sbook)
- })
+ this.props.BookSearch(query)
}
-
- handleChange = (book, shelf) => {
- this.props.onUpdateBook(book, shelf)
- }
-
-
render(){
return(
@@ -34,29 +23,16 @@ class Search extends Component {
- {this.state.sbook && this.state.sbook.length && this.state.sbook.map((sbooks,i)=>(
- -
-
-
-
-
-
-
-
-
{sbooks.title}
-
{sbooks.authors && sbooks.authors.length ? sbooks.authors[0] : 'Unknown Author'}
-
-
+ {this.props.book && this.props.book.length && this.props.book.map((sbooks)=>(
+
))}
-
+
)
}
}
diff --git a/src/icons/add.svg b/src/icons/add.svg
old mode 100644
new mode 100755
diff --git a/src/icons/arrow-back.svg b/src/icons/arrow-back.svg
old mode 100644
new mode 100755
diff --git a/src/icons/arrow-drop-down.svg b/src/icons/arrow-drop-down.svg
old mode 100644
new mode 100755
diff --git a/src/index.css b/src/index.css
old mode 100644
new mode 100755
diff --git a/src/index.js b/src/index.js
old mode 100644
new mode 100755