@@ -23,18 +23,26 @@ interface ServerResponse {
2323 hasNext : boolean ;
2424 storeReadDtos : Store [ ] ;
2525 } ;
26+ error : null ;
2627}
2728
2829// 서버에서 주점 데이터를 가져오는 함수
29- const fetchStores = async ( { pageParam = 0 } ) : Promise < Store [ ] > => {
30+ const fetchStores = async ( {
31+ pageParam = 0 ,
32+ } ) : Promise < { stores : Store [ ] ; hasNext : boolean } > => {
3033 try {
3134 const SERVER_URI = import . meta. env . VITE_SERVER_URI ;
35+ const currentToken = localStorage . getItem ( "accessToken" ) ;
36+
3237 const response = await axios . get < ServerResponse > (
33- `${ SERVER_URI } /admin /stores/all-stores` ,
38+ `${ SERVER_URI } /v1 /stores/all-stores/infinite-scroll ` ,
3439 {
40+ headers : {
41+ Authorization : `Bearer ${ currentToken } ` ,
42+ } ,
3543 params : {
3644 page : pageParam ,
37- size : 20 ,
45+ size : 5 ,
3846 } ,
3947 }
4048 ) ;
@@ -44,7 +52,10 @@ const fetchStores = async ({ pageParam = 0 }): Promise<Store[]> => {
4452 // 서버 응답 구조에 맞게 데이터 추출
4553 if ( response . data . success && response . data . response ?. storeReadDtos ) {
4654 const storeArray = response . data . response . storeReadDtos ;
55+ const hasNext = response . data . response . hasNext ;
56+
4757 console . log ( "추출된 주점 배열:" , storeArray ) ;
58+ console . log ( "hasNext:" , hasNext ) ;
4859
4960 // 삭제된 주점 필터링하고 실제 서버 데이터 그대로 반환
5061 const stores : Store [ ] = storeArray
@@ -55,21 +66,21 @@ const fetchStores = async ({ pageParam = 0 }): Promise<Store[]> => {
5566 } ) ) ;
5667
5768 console . log ( "필터링된 주점 데이터:" , stores ) ;
58- return stores ;
69+ return { stores, hasNext } ;
5970 } else {
6071 console . warn (
6172 "서버 응답이 성공하지 못했거나 데이터가 없습니다:" ,
6273 response . data
6374 ) ;
64- return [ ] ;
75+ return { stores : [ ] , hasNext : false } ;
6576 }
6677 } catch ( error ) {
6778 console . error ( "주점 데이터 로딩 실패:" , error ) ;
6879 if ( axios . isAxiosError ( error ) ) {
6980 console . error ( "응답 상태:" , error . response ?. status ) ;
7081 console . error ( "응답 데이터:" , error . response ?. data ) ;
7182 }
72- return [ ] ;
83+ return { stores : [ ] , hasNext : false } ;
7384 }
7485} ;
7586
@@ -86,9 +97,8 @@ export const useInfiniteStores = () => {
8697 queryFn : fetchStores ,
8798 initialPageParam : 0 ,
8899 getNextPageParam : ( lastPage , allPages ) => {
89- // 서버에서 hasNext를 제공하지만, 일단 기존 로직 유지
90- // 더 이상 데이터가 없으면 undefined 반환
91- if ( lastPage . length < 20 ) {
100+ // 서버에서 받은 hasNext를 기준으로 다음 페이지 여부 결정
101+ if ( ! lastPage . hasNext ) {
92102 return undefined ;
93103 }
94104 return allPages . length ;
@@ -98,7 +108,7 @@ export const useInfiniteStores = () => {
98108 } ) ;
99109
100110 // 모든 페이지의 stores를 하나의 배열로 합치기
101- const stores = data ?. pages . flat ( ) ?? [ ] ;
111+ const stores = data ?. pages . flatMap ( ( page ) => page . stores ) ?? [ ] ;
102112
103113 // 에러 로깅
104114 useEffect ( ( ) => {
0 commit comments