{"version":3,"file":"ProductListingPagePagination-C_-RH8V6-chunk.js","sources":["../../../GSDClient/Scripts/Components/ProductListingPagePagination.tsx"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { IPaginationViewModel } from 'Types/Litium';\n\ninterface IProductListingPagePaginationProps {\n pagination: IPaginationViewModel;\n loadMoreProductsText: string;\n allProductsLoadedText: string;\n getLoadMoreProducts: (\n params: {\n name: string;\n value: string;\n }[]\n ) => void;\n isFetching: boolean;\n}\n\nexport const ProductListingPagePagination = ({\n pagination,\n loadMoreProductsText,\n allProductsLoadedText,\n getLoadMoreProducts,\n isFetching,\n}: IProductListingPagePaginationProps) => {\n const [currentPageIndex, setCurrentIndex] = useState(\n pagination.currentPageIndex\n );\n\n useEffect(() => {\n setCurrentIndex(pagination.currentPageIndex);\n }, [pagination]);\n\n const handleOnClick = () => {\n const nextPagesIndex = currentPageIndex + 1;\n const urlParams = new URLSearchParams(window.location.search);\n urlParams.set('page', `${nextPagesIndex}`);\n\n const currentUrlParams = Array.from(urlParams).map(filterValue => ({\n name: filterValue[0],\n value: filterValue[1],\n }));\n\n const queryState = currentUrlParams\n .map(facet => `${facet.name}=${facet.value}`)\n .join('&');\n\n const urlWithoutQueryString =\n window.location.origin + window.location.pathname;\n\n getLoadMoreProducts(currentUrlParams);\n window.history.replaceState(\n {},\n '',\n `${urlWithoutQueryString}?${queryState}`\n );\n setCurrentIndex(nextPagesIndex);\n };\n\n return (\n
{allProductsLoadedText}
\n )}\n