-
Notifications
You must be signed in to change notification settings - Fork 37
[김찬기] Sprint 10 #297
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
[김찬기] Sprint 10 #297
The head ref may contain hidden characters: "Next-\uAE40\uCC2C\uAE30-sprint10"
Conversation
- 배열이 아닌 값도 처리할 수 있도록 개선 - 중고마켓 : 배열, 자유게시판 : 일반값
- 중고마켓, 자유게시판 두곳에서 사용할 수 있도록 개선
- axios는 400이상에 error를 throw를 해버려서 바로 error페이지로 이동하게 됨 (try,catch필요) - try문안에서는 에러를 발생되면 catch로 잡아서 에러 핸들링하도록 변경 - catch문안에서 redirect, notfound를 쓰고 (예상된 에러), 나머지에러는 error페이지로 이동 (예상하지 못한 에러)
- id가 정확이 없으면 리스트로 이동
| export const COMMENT_PLACEHOLDER: { [key: string]: string } = { | ||
| articles: "댓글을 입력해주세요.", | ||
| products: | ||
| "개인정보를 공유 및 요청하거나, 명예 훼손, 무단 광고, 불법 정보 유포시 모니터링 후 삭제될 수 있으며, 이에 대한 민형사상 책임은 게시자에게 있습니다.", | ||
| }; | ||
|
|
||
| export const COMMENT_TITLE: { [key: string]: string } = { | ||
| articles: "댓글달기", | ||
| products: "문의하기", | ||
| }; | ||
|
|
||
| export const COMMENT_SUBJECT: { [key: string]: string } = { | ||
| articles: "댓글", | ||
| products: "문의", | ||
| }; | ||
|
|
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.
코멘트 컴포넌트를 혹시나 재사용하는 경우에 여기에 필요한 placholder나 문구를 셋팅해두고 하나의 컴포넌트로 쓰도록 해보았습니다.
- 처음에는 코멘트컴포넌트안에서 aritcles이냐 products냐 구분해서 문구들을 분기하려고 했는데, 만약에 다른 페이지가 추가되면 또 분기를 나눠야할것같아서 객체를 만들어두고 키로 접근해서 사용하도록 해봤습니다.
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.
와 너무 잘 하신것같아요ㅋㅋㅋ
이러면 관리하기도 좋고 나중에 추가되었을때 어디를 보아야하는지도 명확해지겠죠?
조금더 typescript를 이용해보면 새로운 타입이 추가되었을때 빌드타임에 에러나게 할 수 있어요.
아래코드를 참고해보면 좋을것같아요!
type ItemType = "articles" | "products";
export const COMMENT_PLACEHOLDER: Record<ItemType, string> = {
articles: "댓글을 입력해주세요.",
products:
"개인정보를 공유 및 요청하거나, 명예 훼손, 무단 광고, 불법 정보 유포시 모니터링 후 삭제될 수 있으며, 이에 대한 민형사상 책임은 게시자에게 있습니다.",
};
export const COMMENT_TITLE: Record<ItemType, string> = {
articles: "댓글달기",
products: "문의하기",
};
export const COMMENT_SUBJECT: Record<ItemType, string> = {
articles: "댓글",
products: "문의",
};이러면 나중에 ItemType에 뭐가 추가되면 연결된 다른곳들 다 에러가 날꺼에요
typescript의 에러를 사용해서 어디를 수정해야할지 빠르게 확인할 수 있겠죠ㅎㅎ
Lanace
left a comment
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.
고생하셨습니다ㅎㅎ !
진짜 잘하시네여 ㅋㅋㅋ
남겨둔 코멘트는 그냥 한번쯤 생각해볼만한 내용이고, 지금 작성해주신 부분도 충분히 좋아요ㅎㅎ
그럼 조금있다가 멘토링떄 뵐게요~
| const [formStatus, formAction, isPending] = useActionState(action, { | ||
| message: "", | ||
| }); |
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.
저도 실무에서 써본적이 없긴 한데, 보니까 써볼만 한것같긴 하네여...!ㅎㅎ
👍
| interface ArticleFormProps { | ||
| initialData?: Article; | ||
| mode?: "add" | "edit"; | ||
| articleId?: number; |
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.
articleId 값은 initialData 에 포함되어있지 않을까요...?
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.
요거는 타입 추론을 이용하면 좋을것같아요.
mode가 add 이면 딱히 initialData나 articleId가 필요없지 않나요...?
type ArticleFormProps = ArticleEditFormProps | ArticleAddFormProps;
type ArticleEditFormProps = {
initialData?: any;
mode: "edit";
articleId?: number;
};
type ArticleAddFormProps = {
mode: "add";
};이런식으로 합성해서 사용할 수 있어요.
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.
오 이거 엄청 고민하던건데 감사합니다.;;;
| const { handleArticleAdd, handleArticleModify } = | ||
| useArticleActions(articleId); | ||
| const onFormSubmit = mode === "add" ? handleArticleAdd : handleArticleModify; |
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.
이건 좀 취향을 탈수도 있는데... 저는 컴포넌트에서 API 통신하는걸 그다지 선호하진 않거든요...
왜냐하면 이 ArticleForm은 단순 Form인데, 결과적으로 이게 submit 되었을떄 add할지 edit할지는 이 컴포넌트를 가져다가 사용하는 사람이 결정하는게 좋다고 생각해서요ㅎㅎ;;
그래서 차라리 ArticleFormProps 에 onSubmit 메소드를 받는게 어떨까 싶어요!
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.
form컴포넌트를 불러서 사용하는쪽에서 원하는 submit기능을 주입하도록 변경하는거네요. 감사합니다. ^^
| image, | ||
| title, | ||
| content, | ||
| writer: { nickname, id: ownerId }, |
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.
👍
| export default function Loading() { | ||
| return <Message>코멘트를 가져오는중입니다...</Message>; | ||
| } |
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.
오 loading.tsx 도 쓸줄아시는군요...! 👍
| export default function ArticleDetailPage() { | ||
| return <></>; |
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.
사용하지 않는 코드는 삭제해도 괜찮을것같아요ㅎㅎ!
| useInfiniteQuery({ | ||
| queryKey: ["comments", name, id], | ||
| queryFn: ({ pageParam = undefined }) => | ||
| getComments(name, { id, cursor: pageParam }), | ||
| getNextPageParam: (lastPage) => lastPage.nextCursor, | ||
| initialPageParam: 0, | ||
| initialData: { | ||
| pageParams: [0], | ||
| pages: [initialComments], | ||
| }, |
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.
이건 문서보고 해보신건가요??
useQuery만 알려드렸던건데 이거까지 쓰실줄은 몰랐는데...ㅋㅋ;;
잘 쓰셨네여ㅎㅎ
요구사항
기본
상품 등록 페이지
상품 상세 페이지
심화
주요 변경사항
스크린샷
멘토에게