|
1 | 1 | /** |
2 | 2 | * External dependencies |
3 | 3 | */ |
4 | | -import { Component } from 'react'; |
| 4 | +import { useState } from '@wordpress/element'; |
5 | 5 | import PropTypes from 'prop-types'; |
6 | | -import withQueryStringValues from '@woocommerce/base-hocs/with-query-string-values'; |
7 | 6 |
|
8 | 7 | /** |
9 | 8 | * Internal dependencies |
10 | 9 | */ |
11 | 10 | import ProductList from './index'; |
12 | 11 |
|
13 | | -class ProductListContainer extends Component { |
14 | | - onPageChange = ( newPage ) => { |
15 | | - this.props.updateQueryStringValues( { |
16 | | - product_page: newPage, |
17 | | - } ); |
| 12 | +const ProductListContainer = ( { attributes } ) => { |
| 13 | + const [ currentPage, setPage ] = useState( 1 ); |
| 14 | + const [ currentSort, setSort ] = useState( attributes.orderby ); |
| 15 | + const onPageChange = ( newPage ) => { |
| 16 | + setPage( newPage ); |
18 | 17 | }; |
19 | | - |
20 | | - onSortChange = ( event ) => { |
| 18 | + const onSortChange = ( event ) => { |
21 | 19 | const newSortValue = event.target.value; |
22 | | - this.props.updateQueryStringValues( { |
23 | | - product_sort: newSortValue, |
24 | | - product_page: 1, |
25 | | - } ); |
| 20 | + setSort( newSortValue ); |
| 21 | + setPage( 1 ); |
26 | 22 | }; |
27 | 23 |
|
28 | | - render() { |
29 | | - // eslint-disable-next-line camelcase |
30 | | - const { attributes, product_page, product_sort } = this.props; |
31 | | - const currentPage = parseInt( product_page ); |
32 | | - const sortValue = product_sort || attributes.orderby; // eslint-disable-line camelcase |
33 | | - |
34 | | - return ( |
35 | | - <ProductList |
36 | | - attributes={ attributes } |
37 | | - currentPage={ currentPage } |
38 | | - onPageChange={ this.onPageChange } |
39 | | - onSortChange={ this.onSortChange } |
40 | | - sortValue={ sortValue } |
41 | | - /> |
42 | | - ); |
43 | | - } |
44 | | -} |
| 24 | + return ( |
| 25 | + <ProductList |
| 26 | + attributes={ attributes } |
| 27 | + currentPage={ currentPage } |
| 28 | + onPageChange={ onPageChange } |
| 29 | + onSortChange={ onSortChange } |
| 30 | + sortValue={ currentSort } |
| 31 | + /> |
| 32 | + ); |
| 33 | +}; |
45 | 34 |
|
46 | 35 | ProductListContainer.propTypes = { |
47 | 36 | attributes: PropTypes.object.isRequired, |
48 | | - // From withQueryStringValues |
49 | | - product_page: PropTypes.oneOfType( [ PropTypes.number, PropTypes.string ] ), |
50 | | - product_sort: PropTypes.string, |
51 | | -}; |
52 | | - |
53 | | -ProductListContainer.defaultProps = { |
54 | | - product_page: 1, |
55 | 37 | }; |
56 | 38 |
|
57 | | -export default withQueryStringValues( [ 'product_page', 'product_sort' ] )( |
58 | | - ProductListContainer |
59 | | -); |
| 39 | +export default ProductListContainer; |
0 commit comments