-
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.
- Loading branch information
Showing
21 changed files
with
287 additions
and
120 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useSuspenseInfiniteQuery } from '@tanstack/react-query'; | ||
import qs from 'qs'; | ||
|
||
import { BOARD_GAMES_WISH_API_URL } from '@/constants/apiRoutes'; | ||
import { BOARD_GAME_WISH_LIST_QUERY_KEY } from '@/constants/queryKey'; | ||
|
||
import type { BoardGameListItemResponse } from './boardGameList'; | ||
import { api } from './core'; | ||
|
||
interface BoardGameWishListResponse { | ||
boardGamesInfos: BoardGameListItemResponse[]; | ||
currentPageNumber: number; | ||
size: number; | ||
hasNext: true; | ||
} | ||
|
||
const getBoardGameWishList = (userId: string, size: number, page: number) => | ||
api.get<BoardGameWishListResponse>({ | ||
url: `${BOARD_GAMES_WISH_API_URL}/${userId}`, | ||
params: { size, page }, | ||
paramsSerializer: params => qs.stringify(params, { indices: false }), | ||
}); | ||
|
||
export const useGetBoardGameWishListApi = ( | ||
userId: string, | ||
size: number = 20, | ||
) => { | ||
const { data, hasNextPage, fetchNextPage, fetchStatus } = | ||
useSuspenseInfiniteQuery({ | ||
queryKey: [BOARD_GAME_WISH_LIST_QUERY_KEY, userId], | ||
queryFn: ({ pageParam }) => getBoardGameWishList(userId, size, pageParam), | ||
initialPageParam: 0, | ||
getNextPageParam: ({ hasNext, currentPageNumber }) => | ||
hasNext ? currentPageNumber + 1 : undefined, | ||
}); | ||
|
||
const allPagesMerged = data.pages.flatMap( | ||
({ boardGamesInfos }) => boardGamesInfos, | ||
); | ||
|
||
return { | ||
fetchStatus, | ||
hasNextPage, | ||
fetchNextPage, | ||
boardGamesInfos: allPagesMerged, | ||
}; | ||
}; |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { HttpResponse, http } from 'msw'; | ||
|
||
import { API_BASE_URL, BOARD_GAMES_WISH_API_URL } from '@/constants/apiRoutes'; | ||
|
||
export const MOCK_GET_BOARD_GAME_WISH_LIST_URL = `${API_BASE_URL}${BOARD_GAMES_WISH_API_URL}/4`; | ||
|
||
export const mockGetBoardGameWishListHandler = async () => { | ||
return HttpResponse.json({ | ||
boardGamesInfos: [ | ||
{ | ||
boardGameId: 1, | ||
name: '스플렌더', | ||
categories: ['전략 게임'], | ||
difficulty: '어려움', | ||
minParticipants: 2, | ||
maxParticipants: 4, | ||
fromPlayTime: 45, | ||
toPlayTime: 45, | ||
wishCount: 54, | ||
imageUrl: 'https://picsum.photos/200', | ||
}, | ||
{ | ||
boardGameId: 2, | ||
name: '노터치 크라켄 (크툴루를 건드리지마)', | ||
categories: ['전략 게임', '파티 게임'], | ||
difficulty: '보통', | ||
minParticipants: 3, | ||
maxParticipants: 6, | ||
fromPlayTime: 30, | ||
toPlayTime: 30, | ||
wishCount: 11, | ||
imageUrl: 'https://picsum.photos/200', | ||
}, | ||
{ | ||
boardGameId: 3, | ||
name: '보난자', | ||
categories: ['전략 게임', '파티 게임', '가족 게임'], | ||
difficulty: '어려움', | ||
minParticipants: 3, | ||
maxParticipants: 7, | ||
fromPlayTime: 50, | ||
toPlayTime: 50, | ||
wishCount: 34, | ||
imageUrl: 'https://picsum.photos/200', | ||
}, | ||
{ | ||
boardGameId: 4, | ||
name: '카탄', | ||
categories: ['전략 게임', '테마 게임'], | ||
difficulty: '어려움', | ||
minParticipants: 3, | ||
maxParticipants: 4, | ||
fromPlayTime: 60, | ||
toPlayTime: 90, | ||
wishCount: 215, | ||
imageUrl: 'https://picsum.photos/200', | ||
}, | ||
{ | ||
boardGameId: 5, | ||
name: '꼬치의 달인', | ||
categories: ['가족게임', '파티 게임', '어린이 게임'], | ||
difficulty: '쉬움', | ||
minParticipants: 2, | ||
maxParticipants: 4, | ||
fromPlayTime: 15, | ||
toPlayTime: 30, | ||
wishCount: 183, | ||
imageUrl: 'https://picsum.photos/200', | ||
}, | ||
{ | ||
boardGameId: 6, | ||
name: '스플렌더', | ||
categories: ['전략 게임'], | ||
difficulty: '어려움', | ||
minParticipants: 2, | ||
maxParticipants: 4, | ||
fromPlayTime: 45, | ||
toPlayTime: 45, | ||
wishCount: 54, | ||
imageUrl: 'https://picsum.photos/200', | ||
}, | ||
{ | ||
boardGameId: 7, | ||
name: '노터치 크라켄 (크툴루를 건드리지마)', | ||
categories: ['전략 게임', '파티 게임'], | ||
difficulty: '보통', | ||
minParticipants: 3, | ||
maxParticipants: 6, | ||
fromPlayTime: 30, | ||
toPlayTime: 30, | ||
wishCount: 11, | ||
imageUrl: 'https://picsum.photos/200', | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
const boardGameWishListMocks = [ | ||
http.get(MOCK_GET_BOARD_GAME_WISH_LIST_URL, mockGetBoardGameWishListHandler), | ||
]; | ||
|
||
export default boardGameWishListMocks; |
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
40 changes: 40 additions & 0 deletions
40
src/pages/BoardGameWishList/components/BoardGameWishList/index.tsx
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,40 @@ | ||
import { useParams } from 'react-router-dom'; | ||
|
||
import { useGetBoardGameWishListApi } from '@/apis/boardGameWishList'; | ||
import EmptyListFullScreen from '@/components/EmptyListFullScreen'; | ||
import InfiniteScrollAutoFetcher from '@/components/InfiniteScrollAutoFetcher'; | ||
import { | ||
EMPTY_BOARD_GAME_WISH_MESSAGE, | ||
EMPTY_BOARD_GAME_WISH_TITLE, | ||
} from '@/constants/messages/emptyScreens'; | ||
import BoardGameListItem from '@/pages/BoardGameList/components/BoardGameList/BoardGameListItem'; | ||
|
||
const BoardGameWishList = () => { | ||
const { userId } = useParams() as { userId: string }; | ||
const { boardGamesInfos, fetchStatus, hasNextPage, fetchNextPage } = | ||
useGetBoardGameWishListApi(userId); | ||
|
||
if (boardGamesInfos.length === 0) { | ||
return ( | ||
<EmptyListFullScreen | ||
title={EMPTY_BOARD_GAME_WISH_TITLE} | ||
message={EMPTY_BOARD_GAME_WISH_MESSAGE} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<InfiniteScrollAutoFetcher | ||
hasNextPage={hasNextPage} | ||
fetchStatus={fetchStatus} | ||
fetchNextPage={fetchNextPage} | ||
className='grow overflow-y-auto overflow-x-hidden' | ||
> | ||
{boardGamesInfos.map(boardGame => ( | ||
<BoardGameListItem key={boardGame.boardGameId} boardGame={boardGame} /> | ||
))} | ||
</InfiniteScrollAutoFetcher> | ||
); | ||
}; | ||
|
||
export default BoardGameWishList; |
Oops, something went wrong.