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.
- Loading branch information
tobias-dev
committed
Apr 24, 2020
1 parent
aa15170
commit f96daab
Showing
3 changed files
with
86 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import Shelf from './Shelf'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const Shelves = (props) => { | ||
const { books, shelves, onBookMove } = props; | ||
|
||
const getBooksByShelf = (shelfId) => { | ||
return books.filter((b) => b.shelf === shelfId); | ||
}; | ||
|
||
return ( | ||
<div className="list-books"> | ||
<div className="list-books-title"> | ||
<h1>MyReads</h1> | ||
</div> | ||
<div className="list-books-content"> | ||
<div> | ||
{shelves.map((shelf) => ( | ||
<Shelf | ||
key={shelf.id} | ||
shelf={shelf} | ||
shelves={shelves} | ||
books={getBooksByShelf(shelf.id)} | ||
onBookMove={onBookMove} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
<div className="open-search"> | ||
<Link to="/search"> | ||
<button>Add a book</button> | ||
</Link> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
Shelves.propTypes = { | ||
books: PropTypes.array.isRequired, | ||
shelves: PropTypes.array.isRequired, | ||
onBookMove: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default Shelves; |