Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit e7ea464

Browse files
authored
Remove with-query-string-values hoc implementation (#1287)
* remove with-query-string-values hoc implementation * remove unnecessary passed in props and clean up proptypes * remove dead code
1 parent 90ca8a7 commit e7ea464

File tree

3 files changed

+20
-260
lines changed

3 files changed

+20
-260
lines changed
Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,39 @@
11
/**
22
* External dependencies
33
*/
4-
import { Component } from 'react';
4+
import { useState } from '@wordpress/element';
55
import PropTypes from 'prop-types';
6-
import withQueryStringValues from '@woocommerce/base-hocs/with-query-string-values';
76

87
/**
98
* Internal dependencies
109
*/
1110
import ProductList from './index';
1211

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 );
1817
};
19-
20-
onSortChange = ( event ) => {
18+
const onSortChange = ( event ) => {
2119
const newSortValue = event.target.value;
22-
this.props.updateQueryStringValues( {
23-
product_sort: newSortValue,
24-
product_page: 1,
25-
} );
20+
setSort( newSortValue );
21+
setPage( 1 );
2622
};
2723

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+
};
4534

4635
ProductListContainer.propTypes = {
4736
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,
5537
};
5638

57-
export default withQueryStringValues( [ 'product_page', 'product_sort' ] )(
58-
ProductListContainer
59-
);
39+
export default ProductListContainer;

assets/js/base/hocs/test/with-query-string-values.js

Lines changed: 0 additions & 123 deletions
This file was deleted.

assets/js/base/hocs/with-query-string-values.js

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)