Skip to content

Commit

Permalink
fix: 방 전체 조회 및 검색 페이지 오류 수정 (#208)
Browse files Browse the repository at this point in the history
* feat: 루틴페이지 에러바운더리 추가

* feat: api 호출 params 생성 로직 수정

* feat: 에러 바운더리 추가
  • Loading branch information
chasj0326 authored Nov 22, 2023
1 parent 56f239f commit 0d9151c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 24 deletions.
22 changes: 13 additions & 9 deletions src/RoomSlide/components/RoomSlide.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Suspense } from 'react';
import { ErrorBoundary } from '@suspensive/react';
import { DAY_TYPE } from '../constants/dayType';
import RoomData from './RoomData';
import RoomDataFallback from './RoomDataFallback';
import { Deffered } from '@/shared/Deffered';
import { NetworkFallback } from '@/shared/ErrorBoundary';
import { DayType } from '@/core/types/Room';

interface RoomSlideProps {
Expand All @@ -19,15 +21,17 @@ const RoomSlide = ({ roomType }: RoomSlideProps) => {
{START} ~ {END}
</div>
</div>
<Suspense
fallback={
<Deffered>
<RoomDataFallback />
</Deffered>
}
>
<RoomData dayType={roomType} />
</Suspense>
<ErrorBoundary fallback={<NetworkFallback />}>
<Suspense
fallback={
<Deffered>
<RoomDataFallback />
</Deffered>
}
>
<RoomData dayType={roomType} />
</Suspense>
</ErrorBoundary>
</div>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/core/api/functions/roomAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const roomAPI = {
},

getRoomsAll: async (params?: RoomsRequestParams) => {
console.log(params);
return await baseInstance.get<TotalRooms>('/rooms', { params });
}
};
Expand Down
14 changes: 11 additions & 3 deletions src/core/api/queries/useSearchRooms.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useSuspenseInfiniteQuery } from '@tanstack/react-query';
import { RoomSelectType } from '@/core/types';
import { RoomSelectType, RoomsRequestParams } from '@/core/types';
import roomAPI from '../functions/roomAPI';

const useSearchRooms = ({
Expand All @@ -12,8 +12,16 @@ const useSearchRooms = ({
return useSuspenseInfiniteQuery({
queryKey: ['rooms', roomType, keyword],

queryFn: ({ pageParam }) =>
roomAPI.getRoomsAll({ roomType, roomId: pageParam, keyword }),
queryFn: ({ pageParam }) => {
const params: RoomsRequestParams = { roomType };
if (pageParam > 0) {
params.roomId = pageParam;
}
if (keyword) {
params.keyword = keyword;
}
return roomAPI.getRoomsAll(params);
},

initialPageParam: 0,

Expand Down
28 changes: 16 additions & 12 deletions src/pages/SearchPage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Suspense, useState } from 'react';
import { ErrorBoundary } from '@suspensive/react';
import { RoomSelectType } from '@/core/types';
import { KeywordContext } from '@/RoomSearch';
import { SearchBar, Selection, ResultList } from '@/RoomSearch';
import { Deffered } from '@/shared/Deffered';
import ResultListFallback from '@/RoomSearch/components/ResultListFallback';
import { NetworkFallback } from '@/shared/ErrorBoundary';

const SearchPage = () => {
const [roomType, setRoomType] = useState<RoomSelectType>('all');
Expand All @@ -22,18 +24,20 @@ const SearchPage = () => {
/>
</div>
<div className="h-full overflow-y-auto px-5 py-4">
<Suspense
fallback={
<Deffered>
<ResultListFallback size={10} />
</Deffered>
}
>
<ResultList
roomType={roomType}
keyword={keyword}
/>
</Suspense>
<ErrorBoundary fallback={<NetworkFallback />}>
<Suspense
fallback={
<Deffered>
<ResultListFallback size={10} />
</Deffered>
}
>
<ResultList
roomType={roomType}
keyword={keyword}
/>
</Suspense>
</ErrorBoundary>
</div>
</div>
</KeywordContext.Provider>
Expand Down

0 comments on commit 0d9151c

Please sign in to comment.