-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/105/my crew api 연결 #109
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2c8278b
✨ Feat: 초안 작성
yulrang aea88e1
Merge branch 'develop' into Feat/105/MyCrewAPI
yulrang 91b6927
✨ Feat: 마이크루페이지 초안 작성
yulrang 013b2de
🚚 Chore: 파일 분리 및 이동
yulrang 58be236
Merge branch 'develop' into Feat/105/MyCrewAPI
yulrang 5faea7f
🚚 Chore: 파일명 변경, 바뀐 백엔드API 적용
yulrang 26d1701
Merge branch 'develop' into Feat/105/MyCrewAPI
yulrang f5472c7
🚚 Chore: 파일명 변경
yulrang ff655e2
🐛 Fix: 주석 해제
yulrang a5fbad9
Merge branch 'develop' into Feat/105/MyCrewAPI
yulrang e466861
♻️ Refactor: pageable 밖으로 빼기
yulrang 9ad835f
🚨 Fix: 빌드 오류 수정
yulrang ad03a87
Merge branch 'develop' into Feat/105/MyCrewAPI
yulrang 4d4dcd9
🐛 Fix: 오류 처리 추가
yulrang e946b5e
🐛 Fix: 팝오버캘린더 동작 개선
yulrang fd76ffb
🐛 Fix: 로딩, 에러 처리 개선
yulrang bdb86e1
🐛 Fix: 리뷰 반영
yulrang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,27 @@ | ||
| import { fetchApi } from '@/src/utils/api'; | ||
| import { MyCrewListResponse, PageableTypes } from '@/src/types/crew-card'; | ||
|
|
||
| export async function getMyCrewHostedList(pageable: PageableTypes) { | ||
| const { page, size, sort = ['string'] } = pageable; | ||
|
|
||
| try { | ||
| const response: { data: MyCrewListResponse } = await fetchApi( | ||
| `/api/crews/hosted?page=${page}&size=${size}&sort=${sort}`, | ||
| { | ||
| method: 'GET', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| credentials: 'include', // 인증 정보를 요청에 포함 | ||
| }, | ||
| ); | ||
| if (!response.data) { | ||
| throw new Error('Failed to get my crew hosted list'); | ||
| } | ||
| return response.data; | ||
| } catch (error) { | ||
| // eslint-disable-next-line no-console | ||
| console.error(`내가 개설한 크루 목록 조회 실패`); | ||
| return null; | ||
| } | ||
| } |
This file contains hidden or 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,27 @@ | ||
| import { fetchApi } from '@/src/utils/api'; | ||
| import { MyCrewListResponse, PageableTypes } from '@/src/types/crew-card'; | ||
|
|
||
| export async function getMyCrewJoinedList(pageable: PageableTypes) { | ||
| const { page, size, sort = ['string'] } = pageable; | ||
|
|
||
| try { | ||
| const response: { data: MyCrewListResponse } = await fetchApi( | ||
| `/api/crews/joined?page=${page}&size=${size}&sort=${sort}`, | ||
| { | ||
| method: 'GET', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| credentials: 'include', // 인증 정보를 요청에 포함 | ||
| }, | ||
| ); | ||
| if (!response.data) { | ||
| throw new Error('Failed to get my crew joined list'); | ||
| } | ||
| return response.data; | ||
| } catch (error) { | ||
| // eslint-disable-next-line no-console | ||
| console.error(`내가 가입한 크루 목록 조회 실패`); | ||
| return null; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,18 @@ | ||
| import { getMyCrewHostedList } from '@/src/_apis/crew/my-crew-hosted-list'; | ||
| import { MyCrewListResponse, PageableTypes } from '@/src/types/crew-card'; | ||
|
|
||
| export function useGetMyCrewHostedQuery({ pageable }: { pageable: PageableTypes }) { | ||
| const { size, sort = ['string'] } = pageable; | ||
| return { | ||
| queryKey: ['myCrewHosted'], | ||
| queryFn: ({ pageParam = 0 }) => | ||
| getMyCrewHostedList({ page: pageParam, size, sort }).then((response) => { | ||
| if (response === undefined || response === null) { | ||
| throw new Error('크루 목록을 불러오는데 실패했습니다.'); | ||
| } | ||
| return response; | ||
| }), | ||
| getNextPageParam: (lastPage: MyCrewListResponse, allPages: MyCrewListResponse[]) => | ||
| lastPage.hasNext ? allPages.length : undefined, | ||
| }; | ||
| } |
This file contains hidden or 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,18 @@ | ||
| import { getMyCrewJoinedList } from '@/src/_apis/crew/my-crew-joined-list'; | ||
| import { MyCrewListResponse, PageableTypes } from '@/src/types/crew-card'; | ||
|
|
||
| export function useGetMyCrewJoinedQuery({ pageable }: { pageable: PageableTypes }) { | ||
| const { size, sort = ['string'] } = pageable; | ||
| return { | ||
| queryKey: ['myCrewJoined'], | ||
| queryFn: ({ pageParam = 0 }) => | ||
| getMyCrewJoinedList({ page: pageParam, size, sort }).then((response) => { | ||
| if (response === undefined || response === null) { | ||
| throw new Error('크루 목록을 불러오는데 실패했습니다.'); | ||
| } | ||
| return response; | ||
| }), | ||
| getNextPageParam: (lastPage: MyCrewListResponse, allPages: MyCrewListResponse[]) => | ||
| lastPage.hasNext ? allPages.length : undefined, | ||
| }; | ||
| } | ||
This file contains hidden or 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,31 @@ | ||
| 'use client'; | ||
|
|
||
| import { Loader } from '@mantine/core'; | ||
| import { useGetMyCrewHostedQuery } from '@/src/_queries/crew/my-crew-hosted-list-query'; | ||
| import { useInfiniteScroll } from '@/src/hooks/use-infinite-scroll'; | ||
| import CrewCardList from '@/src/components/common/crew-list/crew-card-list'; | ||
|
|
||
| export default function MyCrewHostedPage() { | ||
| const { data, status, ref, isFetchingNextPage } = useInfiniteScroll( | ||
| useGetMyCrewHostedQuery({ | ||
| pageable: { page: 0, size: 6, sort: ['createdAt,desc'] }, | ||
| }), | ||
| ); | ||
| return ( | ||
| <div> | ||
| <CrewCardList | ||
| inWhere="my-crew" | ||
| data={data ?? { pages: [], pageParams: [] }} | ||
| isFetchingNextPage={isFetchingNextPage} | ||
| /> | ||
| {status === 'pending' ? ( | ||
| <div className="flex justify-center py-10"> | ||
| <Loader size="sm" /> | ||
| </div> | ||
| ) : ( | ||
| <div ref={ref} className="h-[1px]" /> | ||
| )} | ||
| {status === 'error' && <p className="py-10 text-center">에러가 발생했습니다.</p>} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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,31 @@ | ||
| 'use client'; | ||
|
|
||
| import { Loader } from '@mantine/core'; | ||
| import { useGetMyCrewJoinedQuery } from '@/src/_queries/crew/my-crew-joined-list-query'; | ||
| import { useInfiniteScroll } from '@/src/hooks/use-infinite-scroll'; | ||
| import CrewCardList from '@/src/components/common/crew-list/crew-card-list'; | ||
|
|
||
| export default function MyCrewJoinedPage() { | ||
| const { data, status, ref, isFetchingNextPage } = useInfiniteScroll( | ||
| useGetMyCrewJoinedQuery({ | ||
| pageable: { page: 0, size: 6, sort: ['createdAt,desc'] }, | ||
| }), | ||
| ); | ||
| return ( | ||
| <div> | ||
| <CrewCardList | ||
| inWhere="my-crew" | ||
| data={data ?? { pages: [], pageParams: [] }} | ||
| isFetchingNextPage={isFetchingNextPage} | ||
| /> | ||
| {status === 'pending' ? ( | ||
| <div className="flex justify-center py-10"> | ||
| <Loader size="sm" /> | ||
| </div> | ||
| ) : ( | ||
| <div ref={ref} className="h-[1px]" /> | ||
| )} | ||
| {status === 'error' && <p className="py-10 text-center">에러가 발생했습니다.</p>} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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,41 @@ | ||
| 'use client'; | ||
|
|
||
| import { ReactNode, useEffect, useState } from 'react'; | ||
| import { usePathname, useRouter } from 'next/navigation'; | ||
| import Tabs from '@/src/components/common/tab'; | ||
|
|
||
| export default function MyCrewLayout({ children }: { children: ReactNode }) { | ||
| const router = useRouter(); | ||
| const currentPath = usePathname(); | ||
| const myCrewTabs = [ | ||
| { label: '내가 참여한 크루', id: 'joined-crew', route: '/my-crew/joined' }, | ||
| { label: '내가 만든 크루', id: 'hosted-crew', route: '/my-crew/hosted' }, | ||
| ]; | ||
| const [currentTab, setCurrentTab] = useState(myCrewTabs[0].id); | ||
|
|
||
| const handleTabClick = (id: string) => { | ||
| const targetRoute = myCrewTabs.find((tab) => tab.id === id)?.route; | ||
| if (targetRoute) router.push(targetRoute); | ||
| }; | ||
|
Comment on lines
+16
to
+19
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. 🛠️ Refactor suggestion 에러 처리 개선이 필요합니다
다음과 같이 수정해보세요: const handleTabClick = (id: string) => {
const targetRoute = myCrewTabs.find((tab) => tab.id === id)?.route;
- if (targetRoute) router.push(targetRoute);
+ if (targetRoute) {
+ router.push(targetRoute);
+ } else {
+ console.error(`탭 ID ${id}에 해당하는 경로를 찾을 수 없습니다.`);
+ // TODO: 사용자에게 에러 메시지 표시
+ }
};
|
||
|
|
||
| useEffect(() => { | ||
| const activeTabId = myCrewTabs.find((tab) => tab.route === currentPath)?.id; | ||
| if (activeTabId) setCurrentTab(activeTabId); | ||
| }, [currentPath]); | ||
|
|
||
| return ( | ||
| <div className="py-8 md:py-12.5"> | ||
| <div className="px-3 md:px-8 lg:px-11.5"> | ||
| <Tabs | ||
| variant="default" | ||
| tabs={myCrewTabs} | ||
| activeTab={currentTab} | ||
| onTabClick={(id) => { | ||
| handleTabClick(id); | ||
| }} | ||
| /> | ||
| </div> | ||
| <div className="mt-8 px-3 md:px-8 lg:px-11.5">{children}</div> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or 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,40 +1,7 @@ | ||
| 'use client'; | ||
|
|
||
| import { useState } from 'react'; | ||
| import Tabs from '@/src/components/common/tab'; | ||
| import { redirect } from 'next/navigation'; | ||
|
|
||
| export default function MyCrewPage() { | ||
| const myPageTabs = [ | ||
| { label: '내가 참여한 크루', id: 'joined-crew' }, | ||
| { label: '내가 만든 크루', id: 'made-crew' }, | ||
| ]; | ||
| const [currentTab, setCurrentTab] = useState(myPageTabs[0].id); | ||
|
|
||
| // TODO: fetchCrewData 함수를 사용하여 데이터를 불러오기 : 파라미터 수정 필요 | ||
| // TODO: 리스트와는 다른 데이터를 사용해야해서 우선 주석처리 했습니다. | ||
| // const { data, ref, isFetchingNextPage } = | ||
| // useInfiniteScroll<MyCrewListResponse>(useGetCrewListQuery()); | ||
|
|
||
| return ( | ||
| <div className="py-8 md:py-12.5"> | ||
| <div className="px-3 md:px-8 lg:px-11.5"> | ||
| <Tabs | ||
| variant="default" | ||
| tabs={myPageTabs} | ||
| activeTab={currentTab} | ||
| onTabClick={(id) => { | ||
| setCurrentTab(id); | ||
| }} | ||
| /> | ||
| </div> | ||
| <div className="mt-8 px-3 md:px-8 lg:px-11.5"> | ||
| {/* <CrewCardList | ||
| inWhere="my-crew" | ||
| data={data} | ||
| ref={ref} | ||
| isFetchingNextPage={isFetchingNextPage} | ||
| /> */} | ||
| </div> | ||
| </div> | ||
| ); | ||
| redirect('/my-crew/joined'); | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🛠️ Refactor suggestion
정렬 파라미터를 더 유연하게 설정하세요.
현재 정렬 파라미터가
['string']으로 고정되어 있어 유연성이 떨어집니다. 이를 외부에서 입력받을 수 있도록 변경하는 것이 좋겠습니다. 예를 들어, 기본값을['createdAt,desc']로 설정하고, 필요에 따라 변경할 수 있도록 합니다.