-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(member): add useBoards API hook (#86)
- Loading branch information
Showing
8 changed files
with
108 additions
and
66 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
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,47 +1,16 @@ | ||
import { getMyHire } from '@api/hire'; | ||
import { getNews } from '@api/news'; | ||
import { getBoards } from '@api/board'; | ||
import { QUERY_KEY } from '@constants/key'; | ||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
import { categoryToTitle } from '@utils/community'; | ||
import type { CommunityCategoryType } from '@type/community'; | ||
import { getBoardsList } from '@api/board'; | ||
import type { PaginationPramsType } from '@type/api'; | ||
|
||
export const useBoards = ( | ||
category: CommunityCategoryType, | ||
page = 0, | ||
size = 6, | ||
) => { | ||
const queryOptions = { | ||
notice: { | ||
queryKey: QUERY_KEY.BORDER_NOTICE, | ||
queryFn: () => getBoardsList(categoryToTitle('notice'), page, size), | ||
}, | ||
free: { | ||
queryKey: QUERY_KEY.BORDER_FREE, | ||
queryFn: () => getBoardsList(categoryToTitle('free'), page, size), | ||
}, | ||
qna: { | ||
queryKey: QUERY_KEY.BORDER_QNA, | ||
queryFn: () => getBoardsList(categoryToTitle('qna'), page, size), | ||
}, | ||
graduated: { | ||
queryKey: QUERY_KEY.BORDER_GRADUATED, | ||
queryFn: () => getBoardsList(categoryToTitle('graduated'), page, size), | ||
}, | ||
news: { | ||
queryKey: QUERY_KEY.NEWS, | ||
queryFn: () => getNews(page, size), | ||
}, | ||
hire: { | ||
queryKey: QUERY_KEY.HIRE, | ||
queryFn: () => getMyHire(page, size), | ||
}, | ||
}; | ||
|
||
const options = queryOptions[category]; | ||
interface UseBoardsParams extends PaginationPramsType {} | ||
|
||
/** | ||
* 커뮤니티 게시글 목록을 조회합니다. | ||
*/ | ||
export const useBoards = ({ page = 0, size = 20 }: UseBoardsParams) => { | ||
return useSuspenseQuery({ | ||
queryKey: [options.queryKey, category, page, size], | ||
queryFn: options.queryFn, | ||
queryKey: [QUERY_KEY.BOARDS], | ||
queryFn: () => getBoards(page, size), | ||
}); | ||
}; |
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,53 @@ | ||
import { getMyHire } from '@api/hire'; | ||
import { getNews } from '@api/news'; | ||
import { QUERY_KEY } from '@constants/key'; | ||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
import { categoryToTitle } from '@utils/community'; | ||
import type { CommunityCategoryType } from '@type/community'; | ||
import { getBoardsList } from '@api/board'; | ||
import { PaginationPramsType } from '@type/api'; | ||
|
||
interface UseBoardsListParams extends PaginationPramsType { | ||
category: CommunityCategoryType; | ||
} | ||
|
||
/** | ||
* 커뮤니티 게시글를 카테고리별로 조회합니다. | ||
*/ | ||
export const useBoardsList = ({ | ||
category, | ||
page = 0, | ||
size = 6, | ||
}: UseBoardsListParams) => { | ||
const queryOptions = { | ||
notice: { | ||
queryKey: QUERY_KEY.BORDER_NOTICE, | ||
queryFn: () => getBoardsList(categoryToTitle('notice'), page, size), | ||
}, | ||
free: { | ||
queryKey: QUERY_KEY.BORDER_FREE, | ||
queryFn: () => getBoardsList(categoryToTitle('free'), page, size), | ||
}, | ||
qna: { | ||
queryKey: QUERY_KEY.BORDER_QNA, | ||
queryFn: () => getBoardsList(categoryToTitle('qna'), page, size), | ||
}, | ||
graduated: { | ||
queryKey: QUERY_KEY.BORDER_GRADUATED, | ||
queryFn: () => getBoardsList(categoryToTitle('graduated'), page, size), | ||
}, | ||
news: { | ||
queryKey: QUERY_KEY.NEWS, | ||
queryFn: () => getNews(page, size), | ||
}, | ||
hire: { | ||
queryKey: QUERY_KEY.HIRE, | ||
queryFn: () => getMyHire(page, size), | ||
}, | ||
}[category]; | ||
|
||
return useSuspenseQuery({ | ||
queryKey: [queryOptions.queryKey, category, page], | ||
queryFn: queryOptions.queryFn, | ||
}); | ||
}; |
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,9 +1,12 @@ | ||
import type { CommunityCategoryKorType } from './community'; | ||
|
||
export interface BoardItem { | ||
export interface BoardType { | ||
id: number; | ||
category: CommunityCategoryKorType; | ||
title: string; | ||
} | ||
|
||
export interface BoardItem extends BoardType { | ||
writer: string; | ||
createdAt: string; | ||
} |