This repository was archived by the owner on Apr 5, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed
Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ class BooksApp extends React.Component {
4646 < Route
4747 path = '/search'
4848 render = { ( { history} ) => (
49- < SearchBooks onHandleChange = { this . handleChange } />
49+ < SearchBooks myBooks = { this . state . books } onHandleChange = { this . handleChange } />
5050 ) }
5151 />
5252
Original file line number Diff line number Diff line change @@ -10,19 +10,27 @@ class SearchBooks extends Component {
1010 constructor ( ) {
1111 super ( ) ;
1212 this . state = {
13- books : [ ]
13+ searchResults : [ ] ,
1414 } ;
1515
1616 this . searchBooks = this . searchBooks . bind ( this ) ;
1717 }
1818
1919 searchBooks ( e ) {
2020 e . preventDefault ( ) ;
21+
2122 const values = serializeForm ( e . target , { hash : true } ) ;
22- console . log ( values . query ) ;
23- BooksAPI . search ( values . query , 20 ) . then ( ( books ) => {
24- console . log ( books ) ;
25- this . setState ( { books} )
23+ const myBooks = this . props . myBooks ;
24+ let findBook = ( book , myBooks ) => {
25+
26+ myBooks . find ( ( bookToFind ) => bookToFind . id === book . id )
27+ } ;
28+
29+ BooksAPI . search ( values . query , 20 ) . then ( ( searchResults ) => {
30+
31+ searchResults . map ( book => findBook ( book , myBooks ) ? book . shelf = findBook ( book , myBooks ) . shelf : book . shelf = 'none' ) ;
32+ this . setState ( { searchResults} )
33+
2634 } )
2735 }
2836
@@ -47,7 +55,7 @@ class SearchBooks extends Component {
4755 </ form >
4856 </ div >
4957 < div className = "search-books-results" >
50- < BooksGrid books = { this . state . books } onHandleChange = { this . props . onHandleChange } />
58+ < BooksGrid books = { this . state . searchResults } onHandleChange = { this . props . onHandleChange } />
5159 </ div >
5260 </ div >
5361 )
You can’t perform that action at this time.
0 commit comments