-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#18] useQuery, useInfiniteQuery -> useSuspenseQuery, useSuspenseInfiniteQuery 교체 #19
Changes from 9 commits
f00c644
e34558e
311011a
512b151
057d78d
5b2ac98
c34bab2
e2776d7
cce87b2
f704bc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ErrorPage, NotFound } from '@/pages'; | ||
|
||
import toast from 'react-hot-toast'; | ||
import { useRouteError } from 'react-router-dom'; | ||
|
||
export const WorkspaceErrorPage = () => { | ||
const error: any = useRouteError(); | ||
const statusCode = error?.response?.statusCode || error?.status; | ||
console.log('error', error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. console.log를 제거를 깜빡하신것 같아유 😊 |
||
if (statusCode === 404) { | ||
toast.error('워크스페이스 정보 불러오기 실패'); | ||
return <NotFound />; | ||
} | ||
return <ErrorPage />; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export { HomePage } from './HomePage/HomePage'; | ||
export { NotFound } from './NotFound/NotFound'; | ||
export { WorkspacePage } from './Workspacepage/WorkspacePage'; | ||
export { ErrorPage } from './ErrorPage/ErrorPage'; | ||
export { WorkspaceErrorPage } from './WorkspaceErrorPage/WorkspaceErrorPage'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,15 @@ import { createUserId, getUserId, removeCssClassNamePrefix } from '@/shared/util | |
import { | ||
useClassBlockStore, | ||
useCssPropsStore, | ||
useImageModalStore, | ||
useResetCssStore, | ||
useWorkspaceChangeStatusStore, | ||
useWorkspaceStore, | ||
useImageModalStore, | ||
} from '@/shared/store'; | ||
|
||
import { WorkspaceApi } from '@/shared/api'; | ||
import toast from 'react-hot-toast'; | ||
import { useEffect } from 'react'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
import { workspaceKeys } from '@/shared/hooks'; | ||
|
||
export const useGetWorkspace = (workspaceId: string) => { | ||
|
@@ -24,29 +23,19 @@ export const useGetWorkspace = (workspaceId: string) => { | |
const { resetChangedStatusState } = useWorkspaceChangeStatusStore(); | ||
const { setIsResetCssChecked } = useResetCssStore(); | ||
const { setInitialImageMap, setInitialImageList } = useImageModalStore(); | ||
const { data, isPending, isError } = useQuery({ | ||
const { data, isPending, isError } = useSuspenseQuery({ | ||
queryKey: workspaceKeys.detail(workspaceId), | ||
queryFn: () => { | ||
resetChangedStatusState(); | ||
return workspaceApi.getWorkspace(userId, workspaceId); | ||
}, | ||
}); | ||
|
||
useEffect(() => { | ||
resetChangedStatusState(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (isError) { | ||
toast.error('워크스페이스 정보 불러오기 실패'); | ||
return; | ||
} | ||
if (!data) { | ||
if (!isError || !data || !data.workspaceDto) { | ||
return; | ||
} | ||
|
||
if (!data.workspaceDto) { | ||
return; | ||
} | ||
Comment on lines
-39
to
-49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if문 최소화 좋네요 👍 |
||
setName(data.workspaceDto.name); | ||
Object.keys(data.workspaceDto.totalCssPropertyObj).forEach((className) => { | ||
createCssClassBlock(className); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { WorkspaceSection } from './WorkspaceSection'; | ||
|
||
const meta: Meta<typeof WorkspaceSection> = { | ||
title: 'widgets/home/WorkspaceSection', | ||
component: WorkspaceSection, | ||
parameters: { | ||
layout: 'fullscreen', | ||
}, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof WorkspaceSection>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
// propsname: value, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { WorkspaceContainer, WorkspaceHeader } from '@/widgets'; | ||
|
||
import { SkeletonWorkspaceList } from '@/shared/ui'; | ||
import { Suspense } from 'react'; | ||
|
||
/** | ||
* | ||
* @description | ||
* 워크스페이스 헤더와 컨테이너를 합친 섹션 컴포넌트 | ||
*/ | ||
export const WorkspaceSection = () => { | ||
return ( | ||
<section className="w-full max-w-[1152px] px-3 pb-48"> | ||
<WorkspaceHeader /> | ||
<Suspense fallback={<SkeletonWorkspaceList skeletonNum={8} />}> | ||
<WorkspaceContainer /> | ||
</Suspense> | ||
</section> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { CustomError } from '../utils/customError'; | ||
import { | ||
BadRequestError, | ||
CustomError, | ||
ForbiddenError, | ||
UnauthorizedError, | ||
} from '../utils/customError'; | ||
import { NextFunction, Request, Response } from 'express'; | ||
|
||
import { NotFound } from '@aws-sdk/client-s3'; | ||
import { errorStatus } from '../utils/constants'; | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
export const errorMiddleware = (err: Error, req: Request, res: Response, _next: NextFunction) => { | ||
console.log(err.constructor.name); | ||
const handler = errorHandlers[err.constructor.name] || errorHandlers['DefaultError']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. console.log를 제거를 깜빡하신것 같아유 😊 222 |
||
console.error(err); | ||
|
||
|
@@ -19,4 +27,16 @@ const errorHandlers: { [key: string]: (err: any, res: Response) => void } = { | |
CustomError: (err: CustomError, res: Response) => { | ||
res.status(err.statusCode).json({ message: err.message }); | ||
}, | ||
NotFoundError: (err: NotFound, res: Response) => { | ||
res.status(errorStatus.HTTP_404_NOT_FOUND).json({ message: err.message }); | ||
}, | ||
BadRequestError: (err: BadRequestError, res: Response) => { | ||
res.status(errorStatus.HTTP_400_BAD_REQUEST).json({ message: err.message }); | ||
}, | ||
UnauthorizedError: (err: UnauthorizedError, res: Response) => { | ||
res.status(errorStatus.HTTP_401_UNAUTHORIZED).json({ message: err.message }); | ||
}, | ||
ForbiddenError: (err: ForbiddenError, res: Response) => { | ||
res.status(errorStatus.HTTP_403_FORBIDDEN).json({ message: err.message }); | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
컴포넌트 의미가 좀 더 명확해져서 좋네요!