-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
전남대 FE_강호정 6주차 과제 #113
전남대 FE_강호정 6주차 과제 #113
Changes from 14 commits
0cbcc15
c58c782
5ac9330
95a609f
a177a32
918c544
5300672
03d65f0
febfaef
5600465
6491ec4
690e92e
57ed942
0fc19b3
13252cf
413aba1
e1954aa
49820ef
9a1274a
7296417
102106f
a7d59bb
d2d4b81
ba289a1
c99bdec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,15 @@ import { getProductsPath } from './useGetProducts'; | |
export const productsMockHandler = [ | ||
rest.get( | ||
getProductsPath({ | ||
categoryId: '2920', | ||
category_id: '2920', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아마 서버 인터페이스로 snake_case를 채택한 것 같은데, 프론트엔드에서 코드 case를 섞어 사용하면 차후 의도를 알아보기 힘들 수도 있고, 가독성을 떨어뜨릴 수도 있습니다. camelCase와 snake_case를 섞어 쓰기 보다는, 카멜케이스로 작성하였으니 서버에서 받는 데이터들도 모두 api interceptor를 통해 카멜케이스로 바꿔서 사용할 수도 있습니다. 그러면 서버 필드가 어떤 case이든지 fe입장에선 카멜케이스로 통일시킬 수 있습니다. 직접 구현할 수도 있고, 이러한 유틸은 라이브러리의 도움을 받을 수도 있습니다. |
||
}), | ||
(_, res, ctx) => { | ||
return res(ctx.json(PRODUCTS_MOCK_DATA)); | ||
}, | ||
), | ||
rest.get( | ||
getProductsPath({ | ||
categoryId: '2930', | ||
category_id: '2930', | ||
}), | ||
(_, res, ctx) => { | ||
return res(ctx.json(PRODUCTS_MOCK_DATA)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import styled from '@emotion/styled'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import { useGetProducts } from '@/api/hooks/useGetProducts'; | ||
import { DefaultGoodsItems } from '@/components/common/GoodsItem/Default'; | ||
import { Container } from '@/components/common/layouts/Container'; | ||
|
@@ -20,12 +19,22 @@ export const CategoryProductsSection = ({ categoryId }: Props) => { | |
categoryId, | ||
}); | ||
|
||
console.log('Fetched Data:', data); | ||
console.log('isError:', isError); | ||
console.log('isLoading:', isLoading); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이러한 콘솔로그 코드들은 배포 시 꼭 지워야합니다. 현재 프로젝트는 연습용이기는 하지만, 주석만이라도 남기면 좋을것같아요. |
||
|
||
if (isLoading) return <LoadingView />; | ||
if (isError) return <TextView>에러가 발생했습니다.</TextView>; | ||
if (!data) return <></>; | ||
if (data.pages[0].products.length <= 0) return <TextView>상품이 없어요.</TextView>; | ||
if (!data || !data.pages || !Array.isArray(data.pages)) | ||
return <TextView>상품이 없어요.</TextView>; | ||
|
||
const flattenGoodsList = data.pages | ||
.flatMap((page) => page?.products ?? []) | ||
.filter((product) => product && product.id && product.name && product.price); | ||
|
||
console.log('Flatten Goods List:', flattenGoodsList); | ||
|
||
const flattenGoodsList = data.pages.map((page) => page?.products ?? []).flat(); | ||
if (flattenGoodsList.length === 0) return <TextView>유효한 상품이 없어요.</TextView>; | ||
|
||
return ( | ||
<Wrapper> | ||
|
@@ -37,11 +46,11 @@ export const CategoryProductsSection = ({ categoryId }: Props) => { | |
}} | ||
gap={16} | ||
> | ||
{flattenGoodsList.map(({ id, imageUrl, name, price }) => ( | ||
{flattenGoodsList.map(({ id, image_url, name, price }) => ( | ||
<Link key={id} to={getDynamicPath.productsDetail(id)}> | ||
<DefaultGoodsItems | ||
key={id} | ||
imageSrc={imageUrl} | ||
imageSrc={image_url} | ||
title={name} | ||
amount={price} | ||
subtitle={''} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기로 접속하면 에러가 뜨는데요. 프론트 배포된 것 맞을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아직 에러 수정하고 있습니다..!