Skip to content

Conversation

@SeokChan-Lee
Copy link
Collaborator

요구사항

기본

  • 자유 게시판 페이지 주소는 “/boards” 입니다.
  • 전체 게시글에서 드롭 다운으로 “최신 순” 또는 “좋아요 순”을 선택해서 정렬을 할 수 있습니다.
  • 게시글 목록 조회 api를 사용하여 베스트 게시글, 게시글을 구현합니다.
  • 게시글 title에 검색어가 일부 포함되면 검색이 됩니다.

심화

  • 반응형으로 보여지는 베스트 게시판 개수를 다르게 설정할때 서버에 보내는 pageSize값을 적절하게 설정합니다.
  • [] next의 data prefetch 기능을 사용해봅니다.

주요 변경사항

  • Next.js로 스프린트 미션 9 구현

스크린샷

image
image

멘토에게

  • 셀프 코드 리뷰를 통해 질문 이어가겠습니다.

@SeokChan-Lee SeokChan-Lee requested a review from Lanace January 22, 2025 04:33
@SeokChan-Lee SeokChan-Lee added the 순한맛🐑 마음이 많이 여립니다.. label Jan 22, 2025
@SeokChan-Lee
Copy link
Collaborator Author

PR을 올리고 보니 assets 디렉토리가 pages 안에 있어, 다음 미션에는 public 디렉토리로 옮겨서 올리도록 하겠습니다.

Copy link
Collaborator

@Lanace Lanace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

개발하시느라 시간 많이 드셨을것같은데 고생 많으셨어요ㅠ

아마 반복되는 코드들이 많이 있다고 느끼셨을텐데, 그런 부분들이 처음에 많이 드는게 정상이긴 해요ㅎㅎ
오히려 그런 생각이 드는게 좋은거기도 하구요...!

비슷한 코드가 나오면 어떻게 공통화 하는게 좋을지, 실제로 공통화 했을때 좋았는지를 생각해보면서 개발하시다보면 분명 더 좋은 코드가 되어있을꺼에요~!!

고생 많으셨습니다ㅎㅎ

orderBy: "recent" | "like" = "recent",
keyword: string = ""
): Promise<ArticleListResponse> {
const url = `https://panda-market-api.vercel.app/articles?page=${page}&pageSize=${pageSize}&orderBy=${orderBy}&keyword=${keyword}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게되면 가독성이 좋진 않은것같아요ㅠ
그리고 서버에 따라서는 keyword가 처럼 공백문자인 경우에 이상한 값을 줄수있어서 optional이라면 아에 안보내는게 조금더 좋아요ㅎㅎ;;

그래서 이런식으로 하면 어떨까요?
나중에 추가되는 값을 바로바로 볼 수 있고, 다루기도 쉬울것같아서요!

const url = new URL("https://panda-market-api.vercel.app/articles");

url.searchParams.append("page", page.toString());
url.searchParams.append("pageSize", pageSize.toString());
url.searchParams.append("orderBy", orderBy);
url.searchParams.append("keyword", keyword);

Comment on lines +20 to +26
} catch (error) {
console.error("Error fetching articles:", error);
return {
totalCount: 0,
list: [],
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

차라리 실패했을땐 error를 throw 하는게 좀더 좋을 수 있어요ㅎㅎ

throw new Error(error);

Comment on lines +4 to +6
images: {
domains: ["sprint-fe-project.s3.ap-northeast-2.amazonaws.com"], // 허용할 도메인 추가
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용하지 않는 파일은 아에 삭제하는게 좋을것같아요ㅎㅎ!

export default function Document() {
return (
<Html lang="en">
<Html lang="ko">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

꼼꼼하시네요ㅎㅎ 👍

Comment on lines +74 to +81
<AddItemForm
label="판매가격"
id="price"
type="text"
placeholder="판매가격을 입력해주세요"
value={price}
onChange={handleChange}
/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

가격도 물론 string 으로 처리할 순 있긴 하겠지만 가능하면 number로 처리하는게 좋지 않을까여?ㅎㅎ

Comment on lines +4 to +17
interface AddItemFormProps {
label: string;
type?: string;
placeholder: string;
id: string;
value: string;
onChange: (
event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
) => void;
isTextArea?: boolean;
onKeyDown?: (
event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>
) => void;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

너무 범용으로 만들려고 하신건 아닐까 싶긴 하네여ㅠ

textarea도 되고, input도 되게 만들려고 하다보니 너무 많은 타입들이 생기게 되었는데, 차라리 나눠두는게 사용하긴 더 편하실꺼에요~

Comment on lines +37 to +40
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error}</p>;

return (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

예외처리들 다 잘 처리하셨네요ㅎㅎ!

Comment on lines +25 to +32
try {
const data: Item[] = await getItems();
setItems(data);
setLoading(false);
} catch (err: any) {
setError(err.message);
setLoading(false);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

만약 처음 요청할때 error 가 발생해서 setError 에 들어왔고,
다음번 요청할떄 성공하면 계속 error가 설정되어있어서 에러화면이 보일것같아요ㅠ

try쪽으로 들어오기전에 setError 로 에러를 초기화 해줘야할것같은데여...?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setLoading 도 같이 초기화 해야겠네요!

Comment on lines +18 to +20
const sortedItems = items
.sort((a, b) => b.favoriteCount - a.favoriteCount)
.slice(0, 4);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 값은 useMemo를 이용해보시면 좀더 성능이 좋은 컴포넌트를 만드실 수 있을거에요~!

@Lanace Lanace merged commit f357fa3 into codeit-bootcamp-frontend:Next-이석찬 Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

순한맛🐑 마음이 많이 여립니다..

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants