From 2ca9f5eca2a39a95659f8500a2dddcf6c54c68d7 Mon Sep 17 00:00:00 2001 From: Darren Ethier Date: Tue, 19 Nov 2019 06:20:23 -0500 Subject: [PATCH] Fix: Page selection will reset to 1 after deselecting filterable item, re-sorting products, and selecting new page. (https://github.com/woocommerce/woocommerce-blocks/pull/1205) * initial commit * change initialization state when user triggered page change --- .../assets/js/base/components/product-list/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/woocommerce-blocks/assets/js/base/components/product-list/index.js b/plugins/woocommerce-blocks/assets/js/base/components/product-list/index.js index da2dc059341..a62b74fd6f0 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/product-list/index.js +++ b/plugins/woocommerce-blocks/assets/js/base/components/product-list/index.js @@ -56,7 +56,11 @@ const ProductList = ( { scrollToTop, } ) => { const [ queryState ] = useSynchronizedQueryState( - generateQuery( { attributes, sortValue, currentPage } ) + generateQuery( { + attributes, + sortValue, + currentPage, + } ) ); const previousPage = usePrevious( queryState.page ); const isInitialized = useRef( false ); @@ -71,6 +75,7 @@ const ProductList = ( { const { products, totalProducts, productsLoading } = useStoreProducts( queryState ); + useEffect( () => { if ( ! productsLoading ) { isInitialized.current = true; @@ -80,6 +85,7 @@ const ProductList = ( { const onPaginationChange = ( newPage ) => { scrollToTop( { focusableSelector: 'a, button' } ); onPageChange( newPage ); + isInitialized.current = false; }; const getClassnames = () => {