Skip to content

Commit d2abde3

Browse files
committed
feat: add quiz component
1 parent 09a220b commit d2abde3

File tree

5 files changed

+160
-61
lines changed

5 files changed

+160
-61
lines changed

components/mdx/Components.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
33
import dracula from 'react-syntax-highlighter/dist/cjs/styles/prism/dracula'
44
import { CopyToClipboard } from '../CopyToClipboard'
55
import SideDrawer from './SideDrawer'
6-
import Form from './Form'
6+
import Quiz from './Quiz'
77
import Callout from './Callout'
88

99
const Components = {
@@ -42,7 +42,7 @@ const Components = {
4242
),
4343
SideDrawer,
4444
Callout,
45-
Form,
45+
Quiz,
4646
}
4747

4848
export default Components

components/mdx/Form.tsx

Lines changed: 0 additions & 57 deletions
This file was deleted.

components/mdx/Quiz.tsx

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import {
2+
Box,
3+
VStack,
4+
Text,
5+
Button,
6+
Modal,
7+
ModalOverlay,
8+
ModalContent,
9+
ModalHeader,
10+
ModalFooter,
11+
ModalBody,
12+
ModalCloseButton,
13+
} from '@chakra-ui/react'
14+
import React, { FC, useState } from 'react'
15+
16+
interface QuizProps {
17+
quiz: string
18+
}
19+
20+
interface Quiz {
21+
title: string
22+
questions: [
23+
{
24+
question: string
25+
options: [
26+
{
27+
answer: string
28+
correct?: boolean
29+
},
30+
]
31+
},
32+
]
33+
}
34+
35+
const Quiz: FC<QuizProps> = (props: QuizProps) => {
36+
const quiz: Quiz = require(`../../utils/quizzes/${props.quiz}.json`)
37+
const [showQuiz, setShowQuiz] = useState(false)
38+
const [currenQuestionIndex, setCurrentQuestionIndex] = useState(0)
39+
40+
return (
41+
<>
42+
{!showQuiz && (
43+
<Button
44+
colorScheme="yellow"
45+
backgroundColor="yellow.600"
46+
display="flex"
47+
margin="auto"
48+
onClick={() => setShowQuiz(true)}
49+
>
50+
Take quiz
51+
</Button>
52+
)}
53+
54+
<Modal
55+
closeOnOverlayClick={false}
56+
isOpen={showQuiz}
57+
onClose={() => setShowQuiz(false)}
58+
>
59+
<ModalOverlay />
60+
<ModalContent>
61+
<ModalHeader>{quiz.title}</ModalHeader>
62+
<ModalCloseButton />
63+
<ModalBody pb={6}>
64+
<VStack
65+
spacing={4}
66+
background="gray.900"
67+
padding="6"
68+
borderRadius="md"
69+
>
70+
<Text fontWeight="bold" w="100%">
71+
{quiz.questions[currenQuestionIndex].question}
72+
</Text>
73+
<Box
74+
w="100%"
75+
borderRadius="md"
76+
background="gray.600"
77+
padding="3"
78+
cursor="pointer"
79+
>
80+
Transactions
81+
</Box>
82+
<Box
83+
w="100%"
84+
borderRadius="md"
85+
background="yellow.600"
86+
padding="3"
87+
cursor="pointer"
88+
>
89+
Smart Contracts
90+
</Box>
91+
<Box
92+
w="100%"
93+
borderRadius="md"
94+
background="gray.600"
95+
padding="3"
96+
cursor="pointer"
97+
>
98+
Just user wallets have an address
99+
</Box>
100+
<Box
101+
display="flex"
102+
justifyContent="space-between"
103+
w="100%"
104+
alignItems="center"
105+
>
106+
<Text w="100%">{`Question ${currenQuestionIndex + 1}/${
107+
quiz.questions.length
108+
}`}</Text>
109+
<Box w="100%" display="flex">
110+
<Button mx="2">{'< Previous'}</Button>
111+
<Button>{'Next >'}</Button>
112+
</Box>
113+
</Box>
114+
</VStack>
115+
</ModalBody>
116+
117+
<ModalFooter>
118+
<Button
119+
mx="1"
120+
colorScheme="red"
121+
backgroundColor="red.600"
122+
onClick={() => setShowQuiz(false)}
123+
>
124+
Cancel
125+
</Button>
126+
<Button mx="1" colorScheme="green" backgroundColor="green.400">
127+
Submit
128+
</Button>
129+
</ModalFooter>
130+
</ModalContent>
131+
</Modal>
132+
</>
133+
)
134+
}
135+
136+
export default Quiz

pages/lessons/projects/1.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ icons: ['solidity', 'remix']
66

77
# Lesson 1: Intro to Smart Contract Development
88

9+
<Quiz quiz="lesson-1" />
10+
911
## What are we building?
1012

1113
### Where are we going with it? Web what? Smart contract?
@@ -725,7 +727,5 @@ Can a view function modify the state of the blockchain?
725727

726728
What can we use a smart contract for?
727729

728-
<Form />
729-
730730
**Now, go to the community in Discord to share your new Open Sourcerer
731731
powers**......and find the answers too!!!

utils/quizzes/lesson-1.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"title": "Quiz: Lesson 1",
3+
"questions": [
4+
{
5+
"question": "❓ Apart from a user wallet, what else uses a blockchain (Ethereum) address?",
6+
"options": [
7+
{
8+
"answer": "Transactions"
9+
},
10+
{
11+
"answer": "Smart contracts",
12+
"correct": true
13+
},
14+
{
15+
"answer": "Just user wallets have an address"
16+
}
17+
]
18+
}
19+
]
20+
}

0 commit comments

Comments
 (0)