-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* refactor: writer 타입 정의 * feat: CommentList 컴포넌트 구현 (presentaional) * feat: 책 코멘트 query에 suspense 적용 - useBookComments 쿼리 추가 * feat: BookGroupCommentList 구현 (contaier) * feat: BookCommentList 구현 (container) * feat: CommentList 컴포넌트 스토리북 작성 * chore: 사용되지 않는 이전 CommentList 컴포넌트 삭제 * refactor: book comments query key 추가 * refactor: 코멘트 메뉴 관련 props 수정 * feat: 코멘트목록 name, 이벤트 핸들러 props 추가 * refactor: 변수, prop 이름 수정 * fix: storybook props 수정
- Loading branch information
Showing
11 changed files
with
407 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,49 @@ | ||
import { UseQueryOptions, useQuery } from '@tanstack/react-query'; | ||
import { UseQueryOptions } from '@tanstack/react-query'; | ||
|
||
import type { | ||
APIBook, | ||
APIBookCommentPagination, | ||
BookComment, | ||
} from '@/types/book'; | ||
import bookAPI from '@/apis/book'; | ||
import type { APIBook } from '@/types/book'; | ||
import useQueryWithSuspense from '@/hooks/useQueryWithSuspense'; | ||
import bookKeys from './key'; | ||
|
||
const useBookCommentsQuery = ( | ||
const useBookCommentsQuery = <TData = APIBookCommentPagination>( | ||
bookId: APIBook['bookId'], | ||
options?: Pick< | ||
UseQueryOptions<Awaited<ReturnType<typeof bookAPI.getComments>>['data']>, | ||
'onSuccess' | 'onError' | ||
options?: UseQueryOptions< | ||
Awaited<ReturnType<typeof bookAPI.getComments>>['data'], | ||
unknown, | ||
TData | ||
> | ||
) => | ||
useQuery( | ||
['bookComments', bookId], | ||
useQueryWithSuspense( | ||
bookKeys.comments(bookId), | ||
() => bookAPI.getComments(bookId).then(({ data }) => data), | ||
options | ||
); | ||
|
||
export default useBookCommentsQuery; | ||
|
||
const transformBookCommentsData = ({ | ||
bookComments, | ||
}: APIBookCommentPagination) => { | ||
return bookComments.map( | ||
({ contents, createdAt, commentId, userId, userProfileImage, nickname }) => | ||
({ | ||
id: commentId, | ||
writer: { | ||
id: userId, | ||
profileImageSrc: userProfileImage, | ||
name: nickname, | ||
}, | ||
createdAt, | ||
content: contents, | ||
} as BookComment) | ||
); | ||
}; | ||
|
||
export const useBookComments = (bookId: APIBook['bookId']) => | ||
useBookCommentsQuery(bookId, { | ||
select: transformBookCommentsData, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import CommentList from '@/v1/comment/CommentList'; | ||
|
||
const meta: Meta<typeof CommentList> = { | ||
title: 'comment/CommentList', | ||
component: CommentList, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof CommentList>; | ||
|
||
const comments = [ | ||
{ | ||
id: 1, | ||
writer: { | ||
id: 2, | ||
profileImageSrc: 'https://bit.ly/kent-c-dodds', | ||
name: 'Kent C. Dodds', | ||
}, | ||
createdAt: '2023.02.05', | ||
content: '추천해요!', | ||
}, | ||
{ | ||
id: 2, | ||
writer: { | ||
id: 3, | ||
profileImageSrc: 'https://i.pravatar.cc/300', | ||
name: '김계란', | ||
}, | ||
createdAt: '2023.02.07', | ||
content: '읽고 또 읽어도 새로워요. 🫠', | ||
}, | ||
]; | ||
|
||
export const Default: Story = { | ||
args: { | ||
comments, | ||
isEditableComment: ({ writer }) => writer.id === 3, | ||
}, | ||
}; | ||
|
||
export const Hidden: Story = { | ||
args: { | ||
comments, | ||
isHidden: true, | ||
hiddenText: '멤버만 볼 수 있어요 🥲', | ||
}, | ||
}; | ||
|
||
export const Empty: Story = { | ||
args: { | ||
comments: [], | ||
emptyText: `아직 코멘트가 없어요. | ||
첫 코멘트의 주인공이 되어보세요!`, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useMyProfileId } from '@/queries/user/useMyProfileQuery'; | ||
import { useBookComments } from '@/queries/book/useBookCommentsQuery'; | ||
import { isAuthed } from '@/utils/helpers'; | ||
|
||
import CommentList from './CommentList'; | ||
|
||
const BookCommentList = ({ bookId }: { bookId: number }) => { | ||
const { data: comments } = useBookComments(bookId); | ||
const { data: myId } = useMyProfileId({ enabled: isAuthed() }); | ||
|
||
return ( | ||
<CommentList | ||
name={'코멘트'} | ||
comments={comments} | ||
isEditableComment={({ writer }) => writer.id === myId} | ||
emptyText={`아직 코멘트가 없어요. | ||
가장 먼저 코멘트를 남겨보세요!`} | ||
/> | ||
); | ||
}; | ||
|
||
export default BookCommentList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useBookGroupComments } from '@/queries/group/useBookGroupCommentsQuery'; | ||
import { useMyProfileId } from '@/queries/user/useMyProfileQuery'; | ||
import { useBookGroup } from '@/queries/group/useBookGroupQuery'; | ||
import { isAuthed } from '@/utils/helpers'; | ||
|
||
import CommentList from './CommentList'; | ||
|
||
const BookGroupCommentList = ({ groupId }: { groupId: number }) => { | ||
const { data: bookGroupInfo } = useBookGroup(groupId); | ||
const { data: comments } = useBookGroupComments(groupId); | ||
const { data: myId } = useMyProfileId({ enabled: isAuthed() }); | ||
const { isPublic, isMember } = bookGroupInfo; | ||
|
||
const isHidden = !isPublic && !isMember; | ||
|
||
return ( | ||
<CommentList | ||
name={'게시글'} | ||
comments={comments} | ||
isEditableComment={({ writer }) => writer.id === myId} | ||
isHidden={isHidden} | ||
hiddenText={`멤버만 볼 수 있어요 🥲`} | ||
emptyText={`아직 게시글이 없어요. | ||
가장 먼저 게시글을 남겨보세요!`} | ||
/> | ||
); | ||
}; | ||
|
||
export default BookGroupCommentList; |
Oops, something went wrong.