diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-05-24 15:42:31 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-05-24 15:42:31 +0700 |
| commit | 8a9d61b5049b3eeca0dd40429b05dc7e60e26671 (patch) | |
| tree | b21b303bf92e7a19bdfc9d87e0b4fc6f94a0d371 /src/pages/google_merchant | |
| parent | 5b3e86c51c858e14cc7b9acc60ef0446fc5deaab (diff) | |
Update table-data style
Diffstat (limited to 'src/pages/google_merchant')
| -rw-r--r-- | src/pages/google_merchant/products/index.js | 39 |
1 files changed, 23 insertions, 16 deletions
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 ( <div className='grid grid-cols-1 gap-y-3 p-4'> - <h1 className='text-h-lg font-semibold'>Google Merchant:</h1> - {numberArray.map((number) => ( - <a - key={number} - href={`/google_merchant/products/${number + 1}.xml`} - className='block font-medium text-indigo-600' - target='_blank' - rel='noreferrer' - > - Page {number + 1} - </a> - ))} + <h1 className='text-h-lg font-semibold mb-3'>Google Merchant:</h1> + {numberArray.map((number) => { + const currentPage = number + 1 + const remainingProducts = numFound - limit * number + const productCount = currentPage == pageTotal ? remainingProducts : limit + return ( + <a + key={number} + href={`/google_merchant/products/${currentPage}.xml`} + className='block font-medium text-indigo-600' + target='_blank' + rel='noreferrer' + > + Page {currentPage} - ({productCount}) Products + </a> + ) + })} </div> ) } |
