Skip to content

Commit 40933da

Browse files
committed
feat: 추천 브랜드 api 연동
1 parent 89b511a commit 40933da

5 files changed

Lines changed: 65 additions & 64 deletions

File tree

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"allow": [
44
"Bash(gh pr view:*)",
55
"Bash(gh api:*)",
6-
"Bash(npm run lint)"
6+
"Bash(npm run lint)",
7+
"mcp__ide__getDiagnostics"
78
]
89
}
910
}

src/app/page.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
11
import BannerCarouselContainer from '@/components/banner-carousel';
2-
import {
3-
RecommendedCategoryCard,
4-
RecommendCarousel,
5-
RecommendCarouselItem,
6-
RecommendedProductCard,
7-
} from '@/components/recommend-carousel';
8-
import { MAIN_CATEGORIES } from '@/mocks/categories';
92
import MainHeader from '@/components/layout/main-header';
103
import MainNavBar from '@/components/layout/main-nav-bar';
11-
12-
import { BRANDS, MOCK_PRODUCTS } from '@/mocks/brands-and-products';
134
import RecommendedBrandContainer from '@/components/recommend-brand/recommended-brand-container';
145
import RecommendCategoryContainer from '@/components/recommend-carousel/recommend-category-container';
156
import { Suspense } from 'react';
167
import RecommendProductContainer from '@/components/recommend-carousel/recommend-product-container';
17-
// import { api } from '@/lib/api-client';
18-
// import { Advertisement } from '@/types/domain/etc';
19-
// import { Category } from '@/types/domain/category';
208

219
export default async function Home() {
22-
const p1 = MOCK_PRODUCTS.slice(0, 6);
23-
const p2 = MOCK_PRODUCTS.slice(6, 12);
24-
const p3 = MOCK_PRODUCTS.slice(12, 18);
25-
// TODO: 카테고리 데이터를 UI에 연결
26-
// const categories = await api.get<Category[]>('/categories');
2710

2811
return (
2912
<div className="flex flex-col items-center">
@@ -50,7 +33,9 @@ export default async function Home() {
5033
/>
5134
</Suspense>
5235

53-
<RecommendedBrandContainer brands={BRANDS} productLists={[p1, p2, p3]} />
36+
<Suspense fallback={<div>Loading...</div>}>
37+
<RecommendedBrandContainer />
38+
</Suspense>
5439

5540
<MainNavBar />
5641
</div>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use client';
2+
3+
import { useState } from 'react';
4+
import { BrandWithProducts } from '@/types/domain/brand';
5+
import RecommendedBrandHeader from './recommended-brand-header';
6+
import RecommendedBrandGridCard from './recommended-brand-grid-card';
7+
8+
interface RecommendedBrandClientProps {
9+
brands: BrandWithProducts[];
10+
}
11+
12+
export default function RecommendedBrandClient({
13+
brands,
14+
}: RecommendedBrandClientProps) {
15+
const [selectedIndex, setSelectedIndex] = useState<number>(0);
16+
17+
const currentBrand = brands[selectedIndex];
18+
const currentProducts = currentBrand?.products || [];
19+
20+
return (
21+
<div className="flex w-full flex-col p-5">
22+
<RecommendedBrandHeader
23+
brands={brands}
24+
onClick={setSelectedIndex}
25+
selectedIndex={selectedIndex}
26+
/>
27+
28+
<div className="mt-4">
29+
<div className="mt-2 w-full">
30+
{currentProducts.length > 0 ? (
31+
<ul className="grid w-full grid-cols-2 justify-items-center gap-4">
32+
{currentProducts.map((product) => (
33+
<li key={product.id}>
34+
<RecommendedBrandGridCard product={product} />
35+
</li>
36+
))}
37+
</ul>
38+
) : (
39+
<p>No products available for this brand.</p>
40+
)}
41+
</div>
42+
</div>
43+
</div>
44+
);
45+
}
Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,9 @@
1-
'use client';
1+
import { api } from '@/lib/api-client';
2+
import { BrandWithProducts } from '@/types/domain/brand';
3+
import RecommendedBrandClient from './recommended-brand-client';
24

3-
import { Product } from '@/types/domain/product';
4-
import { Brand } from '@/types/domain/brand';
5-
import { useState } from 'react';
6-
import RecommendedBrandHeader from './recommended-brand-header';
7-
import RecommendedBrandGridCard from './recommended-brand-grid-card';
5+
export default async function RecommendedBrandContainer() {
6+
const brands = await api.get<BrandWithProducts[]>('/brands/recommend');
87

9-
interface RecommendedBrandContainerProps {
10-
brands: Brand[];
11-
productLists: Product[][];
12-
}
13-
14-
export default function RecommendedBrandContainer({
15-
brands,
16-
productLists,
17-
}: RecommendedBrandContainerProps) {
18-
const [selectedIndex, setSelectedIndex] = useState<number>(0);
19-
20-
const currentBrand = brands[selectedIndex];
21-
const currentProducts = productLists[selectedIndex] || [];
22-
23-
return (
24-
<div className="flex w-full flex-col p-5">
25-
<RecommendedBrandHeader
26-
brands={brands}
27-
onClick={setSelectedIndex}
28-
selectedIndex={selectedIndex}
29-
/>
30-
31-
<div className="mt-4">
32-
<div className="mt-2 w-full">
33-
{currentProducts.length > 0 ? (
34-
<ul className="grid w-full grid-cols-2 justify-items-center gap-4">
35-
{currentProducts.map((product) => (
36-
<li key={product.id}>
37-
<RecommendedBrandGridCard product={product} />
38-
</li>
39-
))}
40-
</ul>
41-
) : (
42-
<p>No products available for this brand.</p>
43-
)}
44-
</div>
45-
</div>
46-
</div>
47-
);
8+
return <RecommendedBrandClient brands={brands} />;
489
}

src/types/domain/brand.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
import { Product } from './product';
2+
13
// --- Brand ---
24
export interface Brand {
35
id: number;
46
name: string;
57
description?: string;
68
logoImageUrl?: string;
79
}
10+
11+
export interface BrandWithProducts {
12+
id: number;
13+
name: string;
14+
logoImageUrl: string;
15+
products: Product[];
16+
}

0 commit comments

Comments
 (0)