Skip to content

Commit

Permalink
feat: 이벤트 페이지 suspenseQueries를 이용하는 방식으로 변경하여 로딩 중에 빈 화면 대신 화면의 일부를 볼…
Browse files Browse the repository at this point in the history
… 수 있도록 수정
  • Loading branch information
jinhokim98 committed Dec 14, 2024
1 parent 8532ea6 commit d06d256
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
8 changes: 3 additions & 5 deletions client/src/components/Loader/EventLoader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useQueries} from '@tanstack/react-query';
import {useSuspenseQueries} from '@tanstack/react-query';
import {useEffect} from 'react';

import {requestGetEvent} from '@apis/request/event';
Expand All @@ -16,7 +16,7 @@ import QUERY_KEYS from '@constants/queryKeys';
const EventLoader = ({children, ...props}: React.PropsWithChildren<WithErrorHandlingStrategy | null> = {}) => {
const eventId = getEventIdByUrl();

const queries = useQueries({
const queries = useSuspenseQueries({
queries: [
{queryKey: [QUERY_KEYS.event], queryFn: () => requestGetEvent({eventId, ...props})},
{
Expand Down Expand Up @@ -44,9 +44,7 @@ const EventLoader = ({children, ...props}: React.PropsWithChildren<WithErrorHand
}
}, [stepsData.data, stepsData.isSuccess, updateTotalExpenseAmount]);

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

return !isLoading && children;
return children;
};

export default EventLoader;
23 changes: 23 additions & 0 deletions client/src/pages/EventPage/EventPageFallback/EventPageLoading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Flex, Icon, IconButton, MainLayout, TopNav} from '@components/Design';
import {Footer} from '@components/Footer';

const EventPageLoading = () => {
return (
<MainLayout backgroundColor="gray">
<Flex justifyContent="spaceBetween" alignItems="center">
<TopNav>
<TopNav.Item routePath="/">
<IconButton variants="none">
<Icon iconType="heundeut" />
</IconButton>
</TopNav.Item>
<TopNav.Item displayName="홈" routePath="/home" />
<TopNav.Item displayName="관리" routePath="/admin" />
</TopNav>
</Flex>
<Footer />
</MainLayout>
);
};

export default EventPageLoading;
9 changes: 6 additions & 3 deletions client/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const LoginPage = lazy(() => import('@pages/LoginPage'));
const MyPage = lazy(() => import('@pages/MyPage'));
const LoginRedirectPage = lazy(() => import('@pages/LoginPage/LoginRedirectPage'));
const LoginFailFallback = lazy(() => import('@pages/LoginPage/LoginFailFallback'));
const EventPageLoading = lazy(() => import('@pages/EventPage/EventPageFallback/EventPageLoading'));

const router = createBrowserRouter([
{
Expand Down Expand Up @@ -75,9 +76,11 @@ const router = createBrowserRouter([
{
path: ROUTER_URLS.event,
element: (
<EventLoader>
<EventPage />
</EventLoader>
<Suspense fallback={<EventPageLoading />}>
<EventLoader>
<EventPage />
</EventLoader>
</Suspense>
),
children: [
{
Expand Down

0 comments on commit d06d256

Please sign in to comment.