-
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.
feat: integrate seat review list API
- Loading branch information
Showing
8 changed files
with
131 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import { endPoint } from 'constants/endPoint'; | ||
import type { HallDetailResponse } from 'types'; | ||
import { publicAxios } from 'utils'; | ||
import type { HallDetailResponse, SeatReviewResponse } from 'types'; | ||
import { publicAxios, tokenAxios } from 'utils'; | ||
|
||
export const requestGetHallDetails = async (id: string) => { | ||
return await publicAxios.get<HallDetailResponse>(endPoint.GET_CONCERT_HALL(id)); | ||
}; | ||
|
||
export const requestGetSeatReviews = async (query: string) => { | ||
return await tokenAxios.get<SeatReviewResponse>(`${endPoint.GET_SEAT_REVIEW}?${query}`); | ||
}; |
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 +1,2 @@ | ||
export * from './useGetConcertHallDetail'; | ||
export * from './useGetSeatReviews'; |
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,30 @@ | ||
import { useInfiniteQuery } from '@tanstack/react-query'; | ||
|
||
import { requestGetSeatReviews } from 'api'; | ||
import { useAuthStore } from 'stores'; | ||
import type { SeatReview, SeatReviewSort } from 'types'; | ||
|
||
export const useGetSeatReviews = (hallId: string, sortType: SeatReviewSort) => { | ||
const { isLoggedIn } = useAuthStore(['isLoggedIn']); | ||
|
||
const fetchSeatReviews = async (lastId: number | null) => { | ||
if (!isLoggedIn) return []; | ||
|
||
const query = `${lastId ? `lastId=${lastId}&` : ''}size=3&sortType=${sortType}&hallId=${hallId}`; | ||
const { data } = await requestGetSeatReviews(query); | ||
return data.result; | ||
}; | ||
|
||
return useInfiniteQuery<SeatReview[]>({ | ||
queryKey: ['seatReviews', hallId, sortType], | ||
queryFn: ({ pageParam }) => { | ||
const param = pageParam as number | null; | ||
return fetchSeatReviews(param); | ||
}, | ||
initialPageParam: null, | ||
getNextPageParam: (lastPage) => { | ||
const lastData = lastPage[lastPage.length - 1]; | ||
return lastPage.length > 0 ? lastData.reviewId : null; | ||
}, | ||
}); | ||
}; |
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