From 8a9d61b5049b3eeca0dd40429b05dc7e60e26671 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 24 May 2023 15:42:31 +0700 Subject: Update table-data style --- src/pages/google_merchant/products/index.js | 39 +++++++++++++++++------------ 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'src/pages') diff --git a/src/pages/google_merchant/products/index.js b/src/pages/google_merchant/products/index.js index 38b37d29..a1f59d39 100644 --- a/src/pages/google_merchant/products/index.js +++ b/src/pages/google_merchant/products/index.js @@ -1,35 +1,42 @@ import productSearchApi from '@/lib/product/api/productSearchApi' import _ from 'lodash-contrib' +const limit = 5000 + export async function getServerSideProps() { - const limit = 5000 const queries = { limit: 1, priceFrom: 1, fq: 'image_s:["" TO *]' } const products = await productSearchApi({ query: _.toQuery(queries) }) - const pageTotal = Math.ceil(products.response.numFound / limit) + const { numFound } = products.response + const pageTotal = Math.ceil(numFound / limit) - return { props: { pageTotal } } + return { props: { pageTotal, numFound } } } -export default function GoogleMerchantPage({ pageTotal }) { +export default function GoogleMerchantPage({ pageTotal, numFound }) { const numberArray = Array.from({ length: pageTotal }, (_, index) => index) return (
-

Google Merchant:

- {numberArray.map((number) => ( - - Page {number + 1} - - ))} +

Google Merchant:

+ {numberArray.map((number) => { + const currentPage = number + 1 + const remainingProducts = numFound - limit * number + const productCount = currentPage == pageTotal ? remainingProducts : limit + return ( + + Page {currentPage} - ({productCount}) Products + + ) + })}
) } -- cgit v1.2.3