Skip to content

Commit

Permalink
[FE] refactor: 카테고리 로직 수정 (#637)
Browse files Browse the repository at this point in the history
* refactor: json에 image 추가

* refactor: api 수정에 따른 카테고리 로직 수정

* refactor: menuVariant 밖에서 받도록 수정

* refactor: 주소 받아오는 부분 소문자 변경

* chore: 사용하지 않는 상수 제거
  • Loading branch information
hae-on authored Sep 15, 2023
1 parent 3d01ae3 commit 26825ff
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 59 deletions.
42 changes: 12 additions & 30 deletions frontend/src/components/Common/CategoryList/CategoryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,25 @@ import styled from 'styled-components';

import CategoryItem from '../CategoryItem/CategoryItem';

import { MENU_IMAGES, MENU_NAME, STORE_IMAGES, STORE_NAMES } from '@/constants';
import { CATEGORY_TYPE } from '@/constants';
import { useCategoryQuery } from '@/hooks/queries/product';

const MENU_LENGTH = 5;
const STORE_LENGTH = 4;
interface CategoryListProps {
menuVariant: keyof typeof CATEGORY_TYPE;
}

const menuList = Array.from({ length: MENU_LENGTH }, (_, index) => ({
name: MENU_NAME[index],
image: MENU_IMAGES[index],
}));
const CategoryList = ({ menuVariant }: CategoryListProps) => {
const { data: categories } = useCategoryQuery(CATEGORY_TYPE[menuVariant]);

const storeList = Array.from({ length: STORE_LENGTH }, (_, index) => ({
name: STORE_NAMES[index],
image: STORE_IMAGES[index],
}));

const CategoryList = () => {
return (
<CategoryListContainer>
<MenuListWrapper>
{menuList.map((menu, index) => (
<Link key={`menuItem-${index}`} as={RouterLink} to={`products/food?category=${index + 1}`}>
<CategoryListWrapper>
{categories.map((menu) => (
<Link key={menu.id} as={RouterLink} to={`products/${menuVariant.toLowerCase()}?category=${menu.id}`}>
<CategoryItem name={menu.name} image={menu.image} />
</Link>
))}
</MenuListWrapper>
<StoreListWrapper>
{storeList.map((menu, index) => (
<Link key={`menuItem-${index}`} as={RouterLink} to={`products/store?category=${index + 6}`}>
<CategoryItem key={`storeItem-${index}`} name={menu.name} image={menu.image} />
</Link>
))}
</StoreListWrapper>
</CategoryListWrapper>
</CategoryListContainer>
);
};
Expand All @@ -57,12 +44,7 @@ const CategoryListContainer = styled.div`
}
`;

const MenuListWrapper = styled.div`
display: flex;
gap: 20px;
`;

const StoreListWrapper = styled.div`
const CategoryListWrapper = styled.div`
display: flex;
gap: 20px;
`;
19 changes: 0 additions & 19 deletions frontend/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,3 @@ export const ENVIRONMENT = window.location.href.includes('dev') ? 'dev' : 'prod'

export const IMAGE_URL =
ENVIRONMENT === 'dev' ? process.env.S3_DEV_CLOUDFRONT_PATH : process.env.S3_PROD_CLOUDFRONT_PATH;

export const MENU_NAME = ['간편식사', '과자류', '아이스크림', '식품', '음료'] as const;

export const STORE_NAMES = ['CU', 'GS25', '이마트24', '세븐일레븐'] as const;

export const MENU_IMAGES = [
`${IMAGE_URL}food.jpeg`,
`${IMAGE_URL}snack.jpeg`,
`${IMAGE_URL}icecream.jpeg`,
`${IMAGE_URL}ramen.jpeg`,
`${IMAGE_URL}tea.jpeg`,
];

export const STORE_IMAGES = [
`${IMAGE_URL}cu.jpg`,
`${IMAGE_URL}gs.png`,
`${IMAGE_URL}emart24.png`,
`${IMAGE_URL}seven.png`,
];
10 changes: 5 additions & 5 deletions frontend/src/mocks/data/foodCategory.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{ "id": 1, "name": "간편식사" },
{ "id": 2, "name": "과자류" },
{ "id": 3, "name": "아이스크림" },
{ "id": 4, "name": "식품" },
{ "id": 5, "name": "음료" }
{ "id": 1, "name": "간편식사", "image": "https://tqklhszfkvzk6518638.cdn.ntruss.com/product/8801771029052.jpg" },
{ "id": 2, "name": "과자류", "image": "https://tqklhszfkvzk6518638.cdn.ntruss.com/product/8801771029052.jpg" },
{ "id": 3, "name": "아이스크림", "image": "https://tqklhszfkvzk6518638.cdn.ntruss.com/product/8801771029052.jpg" },
{ "id": 4, "name": "식품", "image": "https://tqklhszfkvzk6518638.cdn.ntruss.com/product/8801771029052.jpg" },
{ "id": 5, "name": "음료", "image": "https://tqklhszfkvzk6518638.cdn.ntruss.com/product/8801771029052.jpg" }
]
8 changes: 4 additions & 4 deletions frontend/src/mocks/data/storeCategory.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{ "id": 6, "name": "CU" },
{ "id": 7, "name": "GS25" },
{ "id": 8, "name": "이마트24" },
{ "id": 9, "name": "세븐일레븐" }
{ "id": 6, "name": "CU", "image": "https://tqklhszfkvzk6518638.cdn.ntruss.com/product/8801771029052.jpg" },
{ "id": 7, "name": "GS25", "image": "https://tqklhszfkvzk6518638.cdn.ntruss.com/product/8801771029052.jpg" },
{ "id": 8, "name": "이마트24", "image": "https://tqklhszfkvzk6518638.cdn.ntruss.com/product/8801771029052.jpg" },
{ "id": 9, "name": "세븐일레븐", "image": "https://tqklhszfkvzk6518638.cdn.ntruss.com/product/8801771029052.jpg" }
]
3 changes: 2 additions & 1 deletion frontend/src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const HomePage = () => {
</Heading>
<Spacing size={16} />
<Suspense fallback={null}>
<CategoryList />
<CategoryList menuVariant="FOOD" />
<CategoryList menuVariant="STORE" />
</Suspense>
<Spacing size={15} />
</section>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const isCategoryVariant = (value: string): value is CategoryVariant => {
export interface Category {
id: number;
name: string;
image: string;
}

export interface Tag {
Expand Down

0 comments on commit 26825ff

Please sign in to comment.