class Books extends React.Component {
constructor(props) {
super(props)
this.block = false
this.booksArr = []
this.page = 1
}
componentDidMount() {
const page = {
page: '1'
}
this.props.getBooks(page)
window.addEventListener('scroll', this.onScroll)
}
onScroll = () => {
const windowHeight = window.innerHeight
const documentHeight = document.body.clientHeight
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
if (windowHeight + scrollTop >= documentHeight && !this.block) {
this.page++
this.props.getBooks({page: this.page})
}
}
render() {
const {book: {books, loading}} = this.props
if (loading) return <p>loading</p>
this.booksArr = [...this.booksArr, ...books]
return (
<div className="book">
<table className="highlight">
<thead>
<tr>
<th>Имя</th>
<th>Город</th>
<th>Номер телефона</th>
<th/>
</tr>
</thead>
<tbody>
{
books &&
this.booksArr.map((book) => {
return (
<tr key={book.pbnum}>
<td>{book.pbfirstName} {book.pblastName}</td>
<td>{book.pbcity}</td>
<td>{book.pbphoneNumber}</td>
<td/>
<td>
<Link
className="waves-effect waves-light btn"
to={`/book/${book._id}/edit?allow=true`}
>Редактировать</Link>
</td>
</tr>
)
})
}
</tbody>
</table>
</div>
)
}
}
Books.propTypes = {
getBooks: PropTypes.func.isRequired
}
const mapDispatchToProps = {getBooks}
const mapStateToProps = state => ({
book: state.book
})
export default connect(mapStateToProps, mapDispatchToProps)(Books)
const data = [
{
id: 1,
date: '2017-10-16',
docs: [
{
"date": "2017-10-16 18:11:09",
"name_doc_type": "Приход",
"id": 564564867361369,
"image": "https://www.utkonos.ru/images/photo/3054/3054289H.jpg",
"name": "Аленка карамель 100г Акционный товар Большая скидка",
"price": 73.9,
"quantity": 99,
"removed": 0
},
{
"date": "2017-10-16 18:11:09",
"name_doc_type": "Приход",
"id": 564564867361369,
"image": "https://mariupolcena.com/files/products/9ff44136e6ccb0afb404ad26f727e67d.jpeg",
"name": "Русская картошка чедар 50",
"price": 46.3,
"quantity": 51,
"removed": 0
},
{
"date": "2017-10-16 12:07:07",
"name_doc_type": "Расход",
"id": 564564867361367,
"image": "https://www.utkonos.ru/images/photo/3265/3265004H.jpg",
"name": "Молочный Яблоко 100",
"price": 25.1,
"quantity": 44,
"removed": 0
}
]
}