From c472261f34388a0b76c3e21fec494b8d5f304715 Mon Sep 17 00:00:00 2001 From: Mqdd Date: Wed, 26 Nov 2025 13:47:31 +0700 Subject: popular product now ssr --- src/components/ui/PopularProduct.jsx | 110 ++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 54 deletions(-) (limited to 'src/components/ui') diff --git a/src/components/ui/PopularProduct.jsx b/src/components/ui/PopularProduct.jsx index 92b2a1b6..0740798d 100644 --- a/src/components/ui/PopularProduct.jsx +++ b/src/components/ui/PopularProduct.jsx @@ -1,61 +1,63 @@ -import { popularProductApi } from '@/api/productApi' -import MobileView from '@/core/components/views/MobileView' -import ProductSlider from '@/lib/product/components/ProductSlider' -import { useQuery } from 'react-query' -import { PopularProductSkeleton } from '../skeleton/PopularProductSkeleton' -import DesktopView from '@/core/components/views/DesktopView' -import ProductCard from '@/lib/product/components/ProductCard' -import Link from '@/core/components/elements/Link/Link' +import MobileView from '@/core/components/views/MobileView'; +import DesktopView from '@/core/components/views/DesktopView'; +import ProductSlider from '@/lib/product/components/ProductSlider'; +import ProductCard from '@/lib/product/components/ProductCard'; +import Link from '@/core/components/elements/Link/Link'; +import { PopularProductSkeleton } from '../skeleton/PopularProductSkeleton'; +import { useQuery } from 'react-query'; +import { popularProductApi } from '@/api/productApi'; -const PopularProduct = () => { - const popularProduct = useQuery('popularProduct', popularProductApi()) +export default function PopularProduct({ initialData }) { + const query = useQuery( + 'popularProducts', + popularProductApi(), + { + initialData: initialData ? { products: initialData.products } : undefined, + refetchOnMount: false + } + ); - if (popularProduct.isLoading) return + if (query.isLoading) return ; + + const data = query.data; + + if (!data) return null; return ( - popularProduct.data && ( - <> - -
-

- Produk Ready Stock -

- -

Lihat Semua

-
- + <> + {/* Mobile */} + +
+
+

Produk Ready Stock

+ +

Lihat Semua

+
- - - -
-
-

- Produk Ready Stock -

- -

Lihat Semua

- -
-
- {popularProduct.data && - popularProduct.data.products.map((product) => ( -
- -
- ))} -
+ + +
+ + + {/* Desktop */} + +
+
+

Produk Ready Stock

+ +

Lihat Semua

+
- - - ) - ) -} -export default PopularProduct +
+ {data.products.map((product) => ( +
+ +
+ ))} +
+
+
+ + ); +} -- cgit v1.2.3