Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add button to load more products
Marcin Gębala866425118afc
diff --git a/saleor/static/js/components/CategoryPage.js b/saleor/static/js/components/CategoryPage.jsindex be013ca64b..94726ca759 100644--- a/saleor/static/js/components/CategoryPage.js+++ b/saleor/static/js/components/CategoryPage.js@@ -3,6 +3,8 @@ import Relay from 'react-relay'import ProductList from './ProductList'import ProductFilters from './ProductFilters'+const PAGINATE_BY = 20;+class CategoryPage extends Component {@@ -18,6 +20,12 @@ class CategoryPage extends Component {})}+ onLoadMore = () => {+ this.props.relay.setVariables({+ count: this.props.relay.variables.count + PAGINATE_BY+ })+ }+render() {const category = this.props.category;const attributes = this.props.attributes;@@ -33,7 +41,10 @@ class CategoryPage extends Component {</div><div className="col-md-9"><div className="row">- <ProductList products={category.products} />+ <ProductList+ onLoadMore={this.onLoadMore}+ products={category.products}+ /></div></div></div>@@ -43,7 +54,8 @@ class CategoryPage extends Component {export default Relay.createContainer(CategoryPage, {initialVariables: {- attributesFilter: []+ attributesFilter: [],+ count: PAGINATE_BY},fragments: {category: () => Relay.QL`@@ -60,7 +72,7 @@ export default Relay.createContainer(CategoryPage, {}}}- products (first: 20, attributes: $attributesFilter) {+ products (first: $count, attributes: $attributesFilter) {${ProductList.getFragment('products')}}}diff --git a/saleor/static/js/components/ProductList.js b/saleor/static/js/components/ProductList.jsindex 9ebbfeba2b..dc46ed0387 100644--- a/saleor/static/js/components/ProductList.js+++ b/saleor/static/js/components/ProductList.js@@ -7,16 +7,26 @@ import ProductItem from './ProductItem';class ProductList extends Component {static propTypes = {+ onLoadMore: PropTypes.func.isRequired,products: PropTypes.object};+ onLoadMore = () => this.props.onLoadMore();+render() {- const edges = this.props.products.edges;+ const { edges, pageInfo: { hasNextPage } } = this.props.products;return (<div>- {edges && (edges.map((edge, i) => (- <ProductItem key={i} product={edge.node} />- )))}+ <div>+ {edges && (edges.map((edge, i) => (+ <ProductItem key={i} product={edge.node} />+ )))}+ </div>+ <div>+ {hasNextPage && (+ <button onClick={this.onLoadMore}>Load more</button>+ )}+ </div></div>)}@@ -31,6 +41,9 @@ export default Relay.createContainer(ProductList, {${ProductItem.getFragment('product')}}}+ pageInfo {+ hasNextPage+ }}`,},