forked from IT-Cotato/12th-OnGil-FE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecommended-brand-container.tsx
More file actions
33 lines (28 loc) · 1.09 KB
/
recommended-brand-container.tsx
File metadata and controls
33 lines (28 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { api } from '@/lib/api-client';
import { BrandWithProducts } from '@/types/domain/brand';
import RecommendedBrandClient from './recommended-brand-client';
import { getMyWishlist } from '@/app/actions/wishlist';
export default async function RecommendedBrandContainer() {
const [brandsResult, wishlistResult] = await Promise.allSettled([
api.get<BrandWithProducts[]>('/brands/recommend', {
cache: 'force-cache',
next: { revalidate: 60 },
}),
getMyWishlist(),
]);
const brands = brandsResult.status === 'fulfilled' ? brandsResult.value : [];
const wishlistItems =
wishlistResult.status === 'fulfilled' ? wishlistResult.value : [];
const wishlistByProductId = new Map(
wishlistItems.map((item) => [item.productId, item.wishlistId]),
);
const brandsWithWishlist = brands.map((brand) => ({
...brand,
products: brand.products.map((product) => ({
...product,
isLiked: wishlistByProductId.has(product.id),
wishlistId: wishlistByProductId.get(product.id),
})),
}));
return <RecommendedBrandClient brands={brandsWithWishlist} />;
}