this repo has no description
1import { connection } from 'next/server';
2import { Product } from '#/types/product';
3import { ProductCard } from '#/components/product-card';
4import { delayRecommendedProducts, withDelay } from '#/lib/delay';
5import { getProducts } from '#/lib/products';
6
7export async function RecommendedProducts() {
8 // Tell Next.js to render dynamically at runtime instead of build-time
9 await connection();
10
11 let products: Product[] = await withDelay(
12 getProducts({ exclude: ['1'] }).then((res) => res.json()),
13 delayRecommendedProducts,
14 );
15
16 return (
17 <div className="space-y-6">
18 <div>
19 <div className="text-lg font-medium text-white">
20 Recommended Products for You
21 </div>
22 <div className="text-sm text-gray-400">
23 Based on your preferences and shopping habits
24 </div>
25 </div>
26 <div className="grid grid-cols-4 gap-6">
27 {products.map((product) => (
28 <div key={product.id} className="col-span-2 md:col-span-1">
29 <ProductCard product={product} />
30 </div>
31 ))}
32 </div>
33 </div>
34 );
35}
36
37const shimmer = `relative overflow-hidden before:absolute before:inset-0 before:-translate-x-full before:animate-[shimmer_1.5s_infinite] before:bg-gradient-to-r before:from-transparent before:via-white/10 before:to-transparent`;
38
39function ProductSkeleton() {
40 return (
41 <div className="col-span-4 space-y-4 lg:col-span-1">
42 <div className={`relative h-[167px] rounded-xl bg-gray-900 ${shimmer}`} />
43
44 <div className="h-4 w-full rounded-lg bg-gray-900" />
45 <div className="h-6 w-1/3 rounded-lg bg-gray-900" />
46 <div className="h-4 w-full rounded-lg bg-gray-900" />
47 <div className="h-4 w-4/6 rounded-lg bg-gray-900" />
48 </div>
49 );
50}
51
52export function RecommendedProductsSkeleton() {
53 return (
54 <div className="space-y-6 pb-[5px]">
55 <div className="space-y-2">
56 <div className={`h-6 w-1/3 rounded-lg bg-gray-900 ${shimmer}`} />
57 <div className={`h-4 w-1/2 rounded-lg bg-gray-900 ${shimmer}`} />
58 </div>
59
60 <div className="grid grid-cols-4 gap-6">
61 <ProductSkeleton />
62 <ProductSkeleton />
63 <ProductSkeleton />
64 <ProductSkeleton />
65 </div>
66 </div>
67 );
68}