|
|
|
@ -1,6 +1,5 @@ |
|
|
|
|
import React, { Component } from "react"; |
|
|
|
|
import FilterListIcon from "@material-ui/icons/FilterList"; |
|
|
|
|
import Loader from "~/components/Loader/index"; |
|
|
|
|
import { connect } from "react-redux"; |
|
|
|
|
import { book } from "~/Redux/actions"; |
|
|
|
|
|
|
|
|
@ -27,11 +26,11 @@ const fontSize = { |
|
|
|
|
|
|
|
|
|
class Products extends Component { |
|
|
|
|
state = { |
|
|
|
|
selectedSort: null, |
|
|
|
|
search: null, |
|
|
|
|
selectedFilters: { |
|
|
|
|
level: [], |
|
|
|
|
subject: [], |
|
|
|
|
sort: null, |
|
|
|
|
}, |
|
|
|
|
firstFilters: [ |
|
|
|
|
{ id: 0, value: "محبوب ترین" }, |
|
|
|
@ -53,10 +52,6 @@ class Products extends Component { |
|
|
|
|
degree: "", |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
componentDidMount() { |
|
|
|
|
this.props.getList(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
handleProductSearch = (val) => { |
|
|
|
|
this.setState({ |
|
|
|
|
search: val, |
|
|
|
@ -64,13 +59,22 @@ class Products extends Component { |
|
|
|
|
this.props.searchBook(val); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps, prevState) { |
|
|
|
|
if (prevState.selectedFilters !== this.state.selectedFilters) { |
|
|
|
|
this.props.filterBook(this.state.selectedFilters); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
componentDidMount() { |
|
|
|
|
localStorage.removeItem("filter"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
|
const { dateFilters, degreeFilters, firstFilters } = this.state; |
|
|
|
|
const { loading, list, page } = this.props; |
|
|
|
|
return ( |
|
|
|
|
<> |
|
|
|
|
{window.innerWidth > 1000 ? ( |
|
|
|
|
list ? ( |
|
|
|
|
<> |
|
|
|
|
<div className="products d-flex flex-column"> |
|
|
|
|
<Navbar page={"products"} /> |
|
|
|
@ -80,25 +84,16 @@ class Products extends Component { |
|
|
|
|
<div className="products__body--left d-flex flex-column"> |
|
|
|
|
<Sort |
|
|
|
|
parent={this} |
|
|
|
|
selectedSort={this.state.selectedSort} |
|
|
|
|
selectedSort={this.state.selectedFilters.sort} |
|
|
|
|
/> |
|
|
|
|
<List parent={this} /> |
|
|
|
|
<List /> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
<Footer /> |
|
|
|
|
</> |
|
|
|
|
) : ( |
|
|
|
|
<div |
|
|
|
|
className="d-flex justify-content-center align-items-center" |
|
|
|
|
style={{ height: "100vh", width: "100vw" }} |
|
|
|
|
> |
|
|
|
|
<Loader /> |
|
|
|
|
</div> |
|
|
|
|
) |
|
|
|
|
) : null} |
|
|
|
|
{window.innerWidth < 1000 ? ( |
|
|
|
|
list ? ( |
|
|
|
|
<> |
|
|
|
|
<div className="mobile-products d-flex flex-column"> |
|
|
|
|
<Navbar page={"products"} /> |
|
|
|
@ -115,48 +110,23 @@ class Products extends Component { |
|
|
|
|
<div className="d-flex"> |
|
|
|
|
<Select name="first" options={firstFilters} parent={this} /> |
|
|
|
|
<Select name="date" options={dateFilters} parent={this} /> |
|
|
|
|
<Select |
|
|
|
|
name="degree" |
|
|
|
|
options={degreeFilters} |
|
|
|
|
parent={this} |
|
|
|
|
/> |
|
|
|
|
<Select name="degree" options={degreeFilters} parent={this} /> |
|
|
|
|
</div> |
|
|
|
|
<FilterListIcon style={{ fontSize: 40, color: "#a5a5a5" }} /> |
|
|
|
|
</div> |
|
|
|
|
<div className="mobile-products__list d-flex flex-wrap"> |
|
|
|
|
{this.state.search |
|
|
|
|
? this.props.searchResult.map((item, i) => ( |
|
|
|
|
<Product product={item} key={i} id={i} /> |
|
|
|
|
)) |
|
|
|
|
: list.map((item, i) => ( |
|
|
|
|
<Product product={item} key={i} id={i} /> |
|
|
|
|
))} |
|
|
|
|
</div> |
|
|
|
|
<List search={this.state.search} /> |
|
|
|
|
</div> |
|
|
|
|
</> |
|
|
|
|
) : ( |
|
|
|
|
<div |
|
|
|
|
className="d-flex justify-content-center align-items-center" |
|
|
|
|
style={{ height: "100vh", width: "100vw" }} |
|
|
|
|
> |
|
|
|
|
<Loader /> |
|
|
|
|
</div> |
|
|
|
|
) |
|
|
|
|
) : null} |
|
|
|
|
</> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default connect( |
|
|
|
|
(state) => ({ |
|
|
|
|
list: state.book.list, |
|
|
|
|
searchResult: state.book.searchResult, |
|
|
|
|
loading: state.book.loading, |
|
|
|
|
// status: state.user.status,
|
|
|
|
|
}), |
|
|
|
|
{ getList: book.list, searchBook: book.searchBook } |
|
|
|
|
)(Products); |
|
|
|
|
export default connect((state) => ({}), { |
|
|
|
|
searchBook: book.searchBook, |
|
|
|
|
filterBook: book.filterBook, |
|
|
|
|
})(Products); |
|
|
|
|
|
|
|
|
|
Products.defaultProps = { |
|
|
|
|
sortItems: [ |
|
|
|
|