-
Notifications
You must be signed in to change notification settings - Fork 1
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
[#434] [모임 상세] 독서모임 상세 페이지 api 연결 #441
Changes from 11 commits
a82f62b
2c693fb
b0eb655
7439d06
2486b1e
0480e0a
faebce5
e8eee00
bbb0def
b6a1fcf
bdf9413
2e79f04
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 |
---|---|---|
@@ -1,19 +1,52 @@ | ||
'use client'; | ||
|
||
import { Flex } from '@chakra-ui/react'; | ||
import TopNavigation from '@/ui/Base/TopNavigation'; | ||
import BookGroupInfo from '@/v1/bookGroup/detail/BookGroupInfo'; | ||
import { IconArrowLeft, IconHamburger, IconPost } from '@public/icons'; | ||
|
||
import GroupDetail from '@/ui/Group/GroupDetail'; | ||
import { useBookGroupTitle } from '@/queries/group/useBookGroupQuery'; | ||
import CommentList from '@/v1/bookGroup/detail/CommentList'; | ||
|
||
const GroupDetailPage = ({ | ||
const DetailBookGroupPage = ({ | ||
params: { groupId }, | ||
}: { | ||
params: { groupId: number }; | ||
}) => { | ||
return ( | ||
<Flex direction="column" justify="center"> | ||
<GroupDetail bookGroupId={Number(groupId)} /> | ||
</Flex> | ||
<> | ||
<BookGroupNavigation groupId={groupId} /> | ||
<div className="flex flex-col gap-[2rem]"> | ||
<BookGroupInfo groupId={groupId} /> | ||
<div className="flex flex-col gap-[1rem]"> | ||
<Heading text="게시글" /> | ||
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. ask; 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.
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. @gxxrxn 자세한 설명 감사해요. 말씀대로 사용자 목록을 보여줄 때 재사용할 수 있겠네요..! |
||
<CommentList groupId={groupId} /> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default GroupDetailPage; | ||
export default DetailBookGroupPage; | ||
|
||
const BookGroupNavigation = ({ groupId }: { groupId: number }) => { | ||
const { data: title } = useBookGroupTitle(groupId); | ||
|
||
return ( | ||
<TopNavigation> | ||
<TopNavigation.LeftItem> | ||
<IconArrowLeft /> | ||
</TopNavigation.LeftItem> | ||
<TopNavigation.CenterItem textAlign="left"> | ||
{title} | ||
</TopNavigation.CenterItem> | ||
<TopNavigation.RightItem> | ||
<IconPost /> | ||
<IconHamburger /> | ||
</TopNavigation.RightItem> | ||
</TopNavigation> | ||
); | ||
}; | ||
|
||
const Heading = ({ text }: { text: string }) => ( | ||
<p className=" text-xl font-bold">{text}</p> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import { | |
UseQueryResult, | ||
} from '@tanstack/react-query'; | ||
|
||
export type useQueryOptionWithOutSuspense< | ||
export type UseQueryOptionWithoutSuspense< | ||
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. 👍 |
||
TQueryFnData = unknown, | ||
TError = unknown, | ||
TData = TQueryFnData, | ||
|
@@ -22,7 +22,7 @@ const useQueryWithSuspense = < | |
>( | ||
queryKey: TQueryKey, | ||
queryFunction?: QueryFunction<TQueryFnData, TQueryKey>, | ||
queryOptions?: useQueryOptionWithOutSuspense< | ||
queryOptions?: UseQueryOptionWithoutSuspense< | ||
TQueryFnData, | ||
TError, | ||
TData, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { APIGroupDetail } from '@/types/group'; | ||
|
||
const bookGroupKeys = { | ||
all: ['bookGroup'] as const, | ||
details: () => [...bookGroupKeys.all, 'detail'] as const, | ||
detail: (id: APIGroupDetail['bookGroupId']) => | ||
[...bookGroupKeys.details(), id] as const, | ||
comments: (id: APIGroupDetail['bookGroupId']) => | ||
[...bookGroupKeys.details(), id, 'comments'] as const, | ||
}; | ||
|
||
export default bookGroupKeys; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { QueryOptions } from '@/types/query'; | ||
import { | ||
APIGroupCommentPagination, | ||
APIGroupDetail, | ||
BookGroupComment, | ||
} from '@/types/group'; | ||
|
||
import GroupAPI from '@/apis/group'; | ||
import bookGroupKeys from './key'; | ||
|
||
const transformComments = ({ bookGroupComments }: APIGroupCommentPagination) => | ||
bookGroupComments.map<BookGroupComment>(comment => ({ | ||
id: comment.commentId, | ||
writer: { | ||
id: comment.userId, | ||
profileImageSrc: comment.userProfileImage, | ||
name: comment.nickname, | ||
}, | ||
createdAt: comment.createdAt, | ||
content: comment.contents, | ||
})); | ||
|
||
const useBookGroupCommentsQuery = <TData = APIGroupCommentPagination>( | ||
groupId: APIGroupDetail['bookGroupId'], | ||
select?: QueryOptions<APIGroupCommentPagination, TData>['select'] | ||
) => | ||
useQuery({ | ||
queryKey: bookGroupKeys.comments(groupId), | ||
queryFn: () => | ||
GroupAPI.getGroupComments({ bookGroupId: groupId }).then( | ||
({ data }) => data | ||
), | ||
select, | ||
}); | ||
|
||
export default useBookGroupCommentsQuery; | ||
|
||
export const useBookGroupComments = (groupId: APIGroupDetail['bookGroupId']) => | ||
useBookGroupCommentsQuery(groupId, transformComments); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { APIGroupDetail, BookGroupDetail } from '@/types/group'; | ||
import { QueryOptions } from '@/types/query'; | ||
|
||
import GroupAPI from '@/apis/group'; | ||
import bookGroupKeys from './key'; | ||
|
||
const transformBookGroupDetail = (data: APIGroupDetail) => | ||
({ | ||
title: data.title, | ||
description: data.introduce, | ||
bookId: data.book.id, | ||
owner: { isMe: data.isOwner, id: data.owner.id }, | ||
date: { start: data.startDate, end: data.endDate }, | ||
memberCount: { current: data.currentMemberCount, max: data.maxMemberCount }, | ||
isPublic: data.isPublic, | ||
isMember: data.isGroupMember, | ||
} as BookGroupDetail); | ||
|
||
export const useBookGroupQuery = <TData = APIGroupDetail>( | ||
groupId: APIGroupDetail['bookGroupId'], | ||
select: QueryOptions<APIGroupDetail, TData>['select'] | ||
) => | ||
useQuery({ | ||
queryKey: bookGroupKeys.detail(groupId), | ||
queryFn: () => | ||
GroupAPI.getGroupDetailInfo({ bookGroupId: groupId }).then( | ||
({ data }) => data | ||
), | ||
select, | ||
}); | ||
|
||
export default useBookGroupQuery; | ||
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. ask; 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. 다른 기본 query들이 모두 default로 export 되고 있어서 맞췄습니다! 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. @gxxrxn 아하..! 다른 쿼리들은 한 파일에 하나의 |
||
|
||
export const useBookGroup = (groupId: APIGroupDetail['bookGroupId']) => | ||
useBookGroupQuery(groupId, transformBookGroupDetail); | ||
|
||
export const useBookGroupTitle = (groupId: APIGroupDetail['bookGroupId']) => | ||
useBookGroupQuery(groupId, data => data.title); | ||
Comment on lines
+36
to
+40
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. p2; 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. 저는 오히려 다른 query들과 차이가 있다고 생각해서 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. @gxxrxn select를 사용한걸 보지 못했었네요. 😅 새로운 쿼리를 호출하는 것이 아니라, 쿼리를 통해 파생된 데이터라면 규란님 의견대로 'query'를 붙일 필요가 없어보이네요 👀 |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { APIUser } from '@/types/user'; | ||
|
||
const userKeys = { | ||
all: ['user'] as const, | ||
details: () => [...userKeys.all, 'detail'] as const, | ||
detail: (id: APIUser['userId']) => [...userKeys.details(), id] as const, | ||
me: () => [...userKeys.details(), 'me'] as const, | ||
}; | ||
|
||
export default userKeys; |
This file was deleted.
This file was deleted.
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.
ask;
#440 PR의 코멘트로 이미 남겨두긴 했는데 새로 추가된 두 호스트로 부터 이미지를 받는 경우가 있는건가요?
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.
네! 일부 도서이미지와 프로필 이미지를 해당 도메인에서 받아오더라구요! 관련 에러가 발생해서 추가했어요.