forked from udacity/reactnd-project-myreads-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from helioricardo/search-and-add-books
Search and add books
- Loading branch information
Showing
5 changed files
with
114 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,62 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import Link from 'react-router-dom/Link' | ||
import Book from './Book' | ||
|
||
const BooksSearch = () => { | ||
return ( | ||
<div className="search-books"> | ||
<div className="search-books-bar"> | ||
<Link className="close-search" to="/">Close</Link> | ||
<div className="search-books-input-wrapper"> | ||
<input type="text" placeholder="Search by title or author"/> | ||
class BooksSearch extends React.Component { | ||
state = { | ||
query: '' | ||
} | ||
|
||
handleChange = event => { | ||
const { onSearchBooks } = this.props | ||
const query = event.target.value | ||
|
||
this.setState({ query }) | ||
onSearchBooks(query) | ||
} | ||
|
||
render = () => { | ||
const { searchResults, onMoveBook } = this.props | ||
|
||
return ( | ||
<div className="search-books"> | ||
<div className="search-books-bar"> | ||
<Link className="close-search" to="/">Close</Link> | ||
<div className="search-books-input-wrapper"> | ||
<input | ||
type="text" | ||
placeholder="Search by title or author" | ||
value={ this.state.query } | ||
onChange={ this.handleChange } | ||
/> | ||
</div> | ||
</div> | ||
<div className="search-books-results"> | ||
<ol className="books-grid"> | ||
{searchResults.map(book => ( | ||
<li key={ book.id }> | ||
<Book | ||
shelf={ book.shelf } | ||
image={ book.imageLinks.thumbnail } | ||
title={ book.title } | ||
authors={ (Array.isArray(book.authors)) ? book.authors.join(", ") : null } | ||
onSearchPage | ||
onMoveBook={shelf => onMoveBook(book, shelf) } | ||
/> | ||
</li> | ||
))} | ||
</ol> | ||
</div> | ||
</div> | ||
<div className="search-books-results"> | ||
<ol className="books-grid"></ol> | ||
</div> | ||
</div> | ||
) | ||
) | ||
} | ||
} | ||
|
||
BooksSearch.propTypes = { | ||
searchResults: PropTypes.array, | ||
onSearchBooks: PropTypes.func.isRequired, | ||
onMoveBook: PropTypes.func.isRequired | ||
} | ||
|
||
export default BooksSearch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters