Skip to content

Commit

Permalink
Add loading effect to editor
Browse files Browse the repository at this point in the history
  • Loading branch information
leung018 committed Jun 10, 2024
1 parent f219357 commit b0807ce
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/app/components/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '../../model/mc'
import { useRouter } from 'next/navigation'
import Error from 'next/error'
import LoadingSpinner from './loading'

export class QuestionSetEditorAriaLabel {
// If update of labels in this class, may need also to update e2e test
Expand Down Expand Up @@ -217,6 +218,7 @@ function QuestionSetEditor({
saveQuestionSet: (questionSet: QuestionSet) => OperationResult
}) {
const router = useRouter()
const [isLoading, setLoading] = useState(true)
const [isNotFound, setNotFound] = useState(false)

const questionSetIdRef = useRef<string>('')
Expand All @@ -232,6 +234,7 @@ function QuestionSetEditor({
const questionSet = fetchQuestionSet()
questionSetIdRef.current = questionSet.id
setQuestionSetInput(mapQuestionSetToQuestionSetInput(questionSet))
setLoading(false)
} catch (e) {
if (
e instanceof GetQuestionSetError &&
Expand Down Expand Up @@ -370,6 +373,10 @@ function QuestionSetEditor({
return <Error statusCode={404} />
}

if (isLoading) {
return <LoadingSpinner />
}

return (
<div className="container mx-auto p-4">
<form>
Expand Down

0 comments on commit b0807ce

Please sign in to comment.