-
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
feat/error boundary #1
Open
JayeHa
wants to merge
10
commits into
main
Choose a base branch
from
feat/error-boundary
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d11df2b
feat: react-error-boundary 추가
JayeHa adcd926
chore(quizService): 네트워크 발생 유도
JayeHa 95b4cae
chore: 샘플데이터 한글로 변경
JayeHa 6cc72a0
feat: WithAsyncBoundary HOC 추가
JayeHa 37076ad
feat: QuizFallbackWithSample 컴포넌트 추가
JayeHa 5454543
feat: QuizPage에 withAsyncBoundary 적용
JayeHa 60843b6
chore: update README.md
JayeHa d285eb9
Merge branch 'main' into feat/error-boundary
JayeHa c0f03fa
Merge branch 'main' into feat/error-boundary
JayeHa e164393
Merge branch 'main' into feat/error-boundary
JayeHa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { QuizCard } from "@components/QuizCards"; | ||
import { useQuizStore } from "@store/quizStore"; | ||
|
||
export const Quiz = () => { | ||
const { userAnswerList, setUserAnswer, quizList } = useQuizStore(); | ||
const currentQuiz = quizList[userAnswerList.length]; | ||
|
||
return ( | ||
<QuizCard | ||
quiz={currentQuiz} | ||
total={quizList.length} | ||
current={userAnswerList.length} | ||
handleNextButton={(answer) => { | ||
setUserAnswer(answer); | ||
}} | ||
/> | ||
); | ||
}; |
43 changes: 43 additions & 0 deletions
43
src/components/QuizFallbackWithSample/QuizFallbackWithSample.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { SAMPLE_SHUFFLED_QUIZ_LIST } from "@/data/quizSampleData"; | ||
import { Button } from "@components/Buttons"; | ||
import { Heading } from "@components/Heading"; | ||
import { useQuizStore } from "@store/quizStore"; | ||
import { ReactElement, useState } from "react"; | ||
import { FallbackProps } from "react-error-boundary"; | ||
|
||
type Props = { | ||
Component: ReactElement; | ||
} & FallbackProps; | ||
|
||
export const QuizFallbackWithSample = ({ | ||
resetErrorBoundary, | ||
Component, | ||
}: Props) => { | ||
const { setQuizList } = useQuizStore(); | ||
|
||
const [viewSample, setViewSample] = useState(false); | ||
const handleSampleDataButtonClick = () => { | ||
setQuizList(SAMPLE_SHUFFLED_QUIZ_LIST); | ||
setViewSample(true); | ||
}; | ||
|
||
if (viewSample) { | ||
return Component; | ||
} | ||
|
||
return ( | ||
<div className="mt-14 flex flex-col items-center gap-4 text-center"> | ||
<div className="mb-4 text-8xl">❗️</div> | ||
<Heading level={2}>네트워크 에러가 발생했습니다.</Heading> | ||
|
||
<div className="flex w-full max-w-96 flex-col gap-3"> | ||
<Button variant="outlined" onClick={resetErrorBoundary}> | ||
재시도 | ||
</Button> | ||
<Button onClick={handleSampleDataButtonClick}> | ||
샘플 데이터로 계속 진행하기 | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ReactElement, Suspense, type FC } from "react"; | ||
import { ErrorBoundary, ErrorBoundaryProps } from "react-error-boundary"; | ||
|
||
type WithAsyncBoundary = <P extends object>( | ||
Component: FC<P>, | ||
fallbacks: { | ||
pendingFallback: ReactElement; | ||
rejectedFallback: ErrorBoundaryProps; | ||
}, | ||
) => FC<P>; | ||
|
||
export const withAsyncBoundary: WithAsyncBoundary = | ||
(Component, fallbacks) => (props) => ( | ||
<Suspense fallback={fallbacks.pendingFallback}> | ||
<ErrorBoundary {...fallbacks.rejectedFallback}> | ||
<Component {...props} /> | ||
</ErrorBoundary> | ||
</Suspense> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
import { withSuspense } from "@/hocs/withSuspense"; | ||
import { QuizCard } from "@components/QuizCards"; | ||
import { withAsyncBoundary } from "@/hocs/withAsyncBoundary"; | ||
import { Quiz } from "@components/Quiz/Quiz"; | ||
import { SkeletonQuizCard } from "@components/QuizCards/QuizCard/QuizCard.skeleton"; | ||
import { QuizFallbackWithSample } from "@components/QuizFallbackWithSample/QuizFallbackWithSample"; | ||
import { useQuizListQuery } from "@service/useQuizService"; | ||
import { useQuizStore } from "@store/quizStore"; | ||
|
||
export const QuizPage = withSuspense(() => { | ||
useQuizListQuery(); | ||
const { userAnswerList, setUserAnswer, quizList } = useQuizStore(); | ||
const currentQuiz = quizList[userAnswerList.length]; | ||
|
||
return ( | ||
<QuizCard | ||
quiz={currentQuiz} | ||
total={quizList.length} | ||
current={userAnswerList.length} | ||
handleNextButton={(answer) => { | ||
setUserAnswer(answer); | ||
}} | ||
/> | ||
); | ||
}, SkeletonQuizCard); | ||
export const QuizPage = withAsyncBoundary( | ||
() => { | ||
useQuizListQuery(); | ||
return <Quiz />; | ||
}, | ||
{ | ||
pendingFallback: <SkeletonQuizCard />, | ||
rejectedFallback: { | ||
fallbackRender: ({ error, resetErrorBoundary }) => ( | ||
<QuizFallbackWithSample | ||
error={error} | ||
resetErrorBoundary={resetErrorBoundary} | ||
Component={<Quiz />} | ||
/> | ||
), | ||
}, | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
❗️ 테스트 발생 유도를 위한 작업입니다.