Skip to content

Commit

Permalink
Merge pull request #259 from KakaoFunding/feat/234
Browse files Browse the repository at this point in the history
Feat/234
  • Loading branch information
devkyoung2 authored May 23, 2024
2 parents 88cdb03 + 0e18934 commit bb193d4
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 6 deletions.
20 changes: 20 additions & 0 deletions src/layouts/Home/Thema/ThemaList/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@import 'styles/mixins.module';

.area_thema {
padding-top: 120px;

.txt_title {
@include font(35px, 700);

display: block;
padding-bottom: 40px;
text-align: center;
line-height: 51px;
}

.wrapper_item {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 50px 20px;
}
}
35 changes: 35 additions & 0 deletions src/layouts/Home/Thema/ThemaList/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useQuery } from '@tanstack/react-query';

import ColumnProductItem from 'components/feature/ProductItem/ColumnProductItem';
import Spinner from 'components/ui/Spinner';

import { getThemaItems } from 'services/api/v1/thema';

import styles from './index.module.scss';

type ThemaListProps = { categoryId: number; title: string };

const ThemaList = ({ categoryId, title }: ThemaListProps) => {
const { data: themaItems, isLoading } = useQuery({
queryKey: ['themaItems', categoryId],
queryFn: () => getThemaItems(categoryId),
});

if (isLoading) return <Spinner />;
return (
themaItems && (
<section className={styles.area_thema}>
<strong className={styles.txt_title}>{title}</strong>
<ul className={styles.wrapper_item}>
{themaItems.map((item) => (
<li key={item.productId}>
<ColumnProductItem product={item} size="medium" />
</li>
))}
</ul>
</section>
)
);
};

export default ThemaList;
48 changes: 47 additions & 1 deletion src/layouts/Home/Thema/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
import ThemaList from './ThemaList';

const TITLE = [
'전하고픈 마음 가득 담아',
'센스 넘치는 선물',
'이런 선물 어때요 ?',
'남녀노소 모두 좋아하는 선물',
'반짝반짝 빛나는 마음',
'부담 없이 마음을 전해요',
'말없이 응원하고 싶을 때🍀',
'이런 선물도 좋을 것 같아요.',
'귀여운 게 최고야',
'달콤한 진심을 전하는 선물',
'고마운 사람들에게 전해요🎁',
'변치 않는 마음을 전해요',
'지금 안 사면 손해입니다 🚨',
'전하고픈 마음 가득 담아',
'활용도 높은 집들이 선물',
'마음을 전하는 빛나는 선물',
];

const CATEGORY_ID = [
170, 171, 172, 176, 177, 178, 179, 181, 182, 184, 185, 188, 192, 194, 195,
196, 202, 203, 204, 205,
];

const getRandomCategoryId = () => {
const categoryIdx = Math.floor(Math.random() * CATEGORY_ID.length);
return CATEGORY_ID[categoryIdx];
};

const getRandomTitle = () => {
const titleIdx = Math.floor(Math.random() * TITLE.length);
return TITLE[titleIdx];
};

const Thema = () => {
return <>이런 선물 어때요?</>;
return (
<>
<ThemaList categoryId={getRandomCategoryId()} title={getRandomTitle()} />
<ThemaList categoryId={getRandomCategoryId()} title={getRandomTitle()} />
<ThemaList categoryId={getRandomCategoryId()} title={getRandomTitle()} />
<ThemaList categoryId={getRandomCategoryId()} title={getRandomTitle()} />
<ThemaList categoryId={getRandomCategoryId()} title={getRandomTitle()} />
<ThemaList categoryId={getRandomCategoryId()} title={getRandomTitle()} />
<ThemaList categoryId={getRandomCategoryId()} title={getRandomTitle()} />
</>
);
};

export default Thema;
3 changes: 3 additions & 0 deletions src/pages/Home/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.area_home {
padding-bottom: 200px;
}
10 changes: 5 additions & 5 deletions src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import MainWrapper from 'components/ui/MainWrapper';
import MainBrands from 'layouts/Home/MainBrands';
import MainProducts from 'layouts/Home/MainProducts';
import NowTrending from 'layouts/Home/NowTrending';
import Receiver from 'layouts/Home/Receiver';
import Thema from 'layouts/Home/Thema';
// import MainBrands from 'layouts/Home/MainBrands';
// import MainProducts from 'layouts/Home/MainProducts';
// import NowTrending from 'layouts/Home/NowTrending';

import styles from './index.module.scss';

Expand All @@ -13,9 +13,9 @@ const Home = () => {
<Receiver />
<MainWrapper>
<Thema />
<NowTrending />
{/* <NowTrending />
<MainBrands />
<MainProducts />
<MainProducts /> */}
</MainWrapper>
</section>
);
Expand Down
11 changes: 11 additions & 0 deletions src/services/api/v1/thema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ProductItem } from 'types/productItem';

import { apiV1 } from '.';

export const getThemaItems = async (categoryId: number) => {
const themaItem = await apiV1.get(
`/products?size=4&categoryId=${categoryId}`,
);

return themaItem.data.content as ProductItem[];
};

0 comments on commit bb193d4

Please sign in to comment.