Skip to content

Commit 4f119e9

Browse files
committed
loader
1 parent a53ffed commit 4f119e9

File tree

6 files changed

+50
-4
lines changed

6 files changed

+50
-4
lines changed

app/exam/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Button } from "@azure-fundamentals/components/Button";
88
import QuizExamForm from "@azure-fundamentals/components/QuizExamForm";
99
import { Question } from "@azure-fundamentals/components/types";
1010
import ExamResult from "@azure-fundamentals/components/ExamResult";
11+
import LoadingIndicator from "@azure-fundamentals/components/LoadingIndicator";
1112

1213
const questionsQuery = gql`
1314
query RandomQuestions($range: Int!, $link: String) {
@@ -86,7 +87,7 @@ const Exam: NextPage<{ searchParams: { url: string; name: string } }> = ({
8687
setCurrentQuestion(data?.randomQuestions[0]);
8788
}, [data]);
8889

89-
if (loading) return <p>Loading</p>;
90+
if (loading) return <LoadingIndicator />;
9091
if (error) return <p>Oh no... {error.message}</p>;
9192

9293
const numberOfQuestions = data.randomQuestions.length || 0;

components/ExamQuizForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Button } from "@azure-fundamentals/components/Button";
33
import { FC } from "react";
44
import { useForm } from "react-hook-form";
55
import { Question } from "@azure-fundamentals/components/types";
6+
import LoadingIndicator from "./LoadingIndicator";
67

78
type Props = {
89
isLoading: boolean;
@@ -35,7 +36,7 @@ const ExamQuizForm: FC<Props> = ({
3536
handleNextQuestion(currentQuestionIndex + 1);
3637
};
3738

38-
if (isLoading) return <p>Loading...</p>;
39+
if (isLoading) return <LoadingIndicator />;
3940
const { question, options } = questionSet;
4041

4142
const noOfAnswers = options.filter((el) => el.isAnswer).length;

components/LoadingIndicator.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from "react";
2+
3+
const LoadingIndicator: React.FC = () => {
4+
return (
5+
<div className="loading-container">
6+
<div className="spinner"></div>
7+
</div>
8+
);
9+
};
10+
11+
export default LoadingIndicator;

components/QuizExamForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Question } from "./types";
44
import { FieldArray, FormikProvider, Field, useFormik } from "formik";
55
import { Button } from "./Button";
66
import useResults from "@azure-fundamentals/hooks/useResults";
7+
import LoadingIndicator from "./LoadingIndicator";
78

89
type Props = {
910
isLoading: boolean;
@@ -192,7 +193,7 @@ const QuizExamForm: React.FC<Props> = ({
192193
setSavedAnswers(saved);
193194
};
194195

195-
if (isLoading) return <p>Loading...</p>;
196+
if (isLoading) return <LoadingIndicator />;
196197

197198
return (
198199
<FormikProvider value={formik}>

components/QuizForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Image from "next/image";
55
import SelectionInput from "./SelectionInput";
66
import { Button } from "./Button";
77
import NumberInputComponent from "./NumberInputComponent";
8+
import LoadingIndicator from "./LoadingIndicator";
89

910
type Props = {
1011
isLoading: boolean;
@@ -139,7 +140,7 @@ const QuizForm: FC<Props> = ({
139140
}
140141
};
141142

142-
if (isLoading) return <p>Loading...</p>;
143+
if (isLoading) return <LoadingIndicator />;
143144
//Error Handling for loading issues
144145
if (!questionSet) {
145146
handleNextQuestion(1);

styles/globals.css

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
11
@tailwind base;
22
@tailwind components;
33
@tailwind utilities;
4+
5+
.loading-container {
6+
position: fixed;
7+
top: 0;
8+
left: 0;
9+
width: 100%;
10+
height: 100%;
11+
display: flex;
12+
justify-content: center;
13+
align-items: center;
14+
z-index: 9999;
15+
}
16+
17+
.spinner {
18+
border: 8px solid rgba(255, 255, 255, 0.3);
19+
border-top: 8px solid #1E293B;
20+
border-radius: 50%;
21+
width: 60px;
22+
height: 60px;
23+
animation: spin 1s linear infinite;
24+
}
25+
26+
@keyframes spin {
27+
0% {
28+
transform: rotate(0deg);
29+
}
30+
100% {
31+
transform: rotate(360deg);
32+
}
33+
}
34+

0 commit comments

Comments
 (0)