Skip to content

Commit

Permalink
refactor: 이벤트 페이지 api 호출 개선 (#686)
Browse files Browse the repository at this point in the history
* refactor: event loader를 이용해서 이벤트에 필요한 정보 병렬적으로 데이터 불러옴

* refactor: 총 금액 업데이트 계산을 로더에서 제거
  • Loading branch information
jinhokim98 authored Oct 2, 2024
1 parent 986bcf1 commit 5d5d9f1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
34 changes: 34 additions & 0 deletions client/src/components/Loader/EventLoader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {useQueries} from '@tanstack/react-query';

import {requestGetEvent} from '@apis/request/event';
import {requestGetReports} from '@apis/request/report';
import {requestGetSteps} from '@apis/request/step';
import {WithErrorHandlingStrategy} from '@errors/RequestGetError';

import getEventIdByUrl from '@utils/getEventIdByUrl';

import QUERY_KEYS from '@constants/queryKeys';

const EventLoader = ({children, ...props}: React.PropsWithChildren<WithErrorHandlingStrategy | null> = {}) => {
const eventId = getEventIdByUrl();

const queries = useQueries({
queries: [
{queryKey: [QUERY_KEYS.event], queryFn: () => requestGetEvent({eventId, ...props})},
{
queryKey: [QUERY_KEYS.reports],
queryFn: () => requestGetReports({eventId, ...props}),
},
{
queryKey: [QUERY_KEYS.steps],
queryFn: () => requestGetSteps({eventId, ...props}),
},
],
});

const isLoading = queries.some(query => query.isLoading === true);

return !isLoading && children;
};

export default EventLoader;
12 changes: 10 additions & 2 deletions client/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {lazy, Suspense} from 'react';

import ErrorPage from '@pages/ErrorPage/ErrorPage';
import EventLoginPage from '@pages/EventPage/AdminPage/EventLoginPage';
import EventLoader from '@components/Loader/EventLoader';

import {EventPage} from '@pages/EventPage';

Expand Down Expand Up @@ -40,9 +41,16 @@ const router = createBrowserRouter([
},
{
path: ROUTER_URLS.event,
element: <EventPage />,
element: (
<EventLoader>
<EventPage />
</EventLoader>
),
children: [
{path: ROUTER_URLS.eventManage, element: <AdminPage />},
{
path: ROUTER_URLS.eventManage,
element: <AdminPage />,
},
{path: ROUTER_URLS.home, element: <HomePage />},
{
path: ROUTER_URLS.eventLogin,
Expand Down

0 comments on commit 5d5d9f1

Please sign in to comment.