You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

298 lines
14 KiB

  1. ![React Quiz App Template Cover Image](./src/assets/images/ReactJS-Quiz-App-Template.jpg)
  2. # Xeven Quiz - ReactJS Quiz App Template
  3. With **Xeven Quiz**, you don't have to spend hours on coding from scratch. This Quiz App template provides a solid foundation, eliminating the need to reinvent the wheel. You'll spend less time developing your app, which lets you focus on the unique.
  4. Xeven Quiz helps you follow industry best practices and coding conventions as a beginner.
  5. As a beginner developer, a quiz app is a common project. But without guidance, this simple project can become difficult.
  6. Xeven Quiz is here to change that narrative and give you the tools and knowledge you need to create a successful and efficient quiz app.
  7. With a strong architecture and modular design, you can easily add new features, expand your question database, and accommodate a growing user base without experiencing any setbacks.
  8. ### Powerful Tech Stack
  9. - Reactjs
  10. - Typescript
  11. - Styled components
  12. With **ReactJS** at its core, it lets you design dynamic interfaces that automatically update and respond to user interactions.
  13. **TypeScript** brings enhanced development productivity through static typing and intelligent tooling.
  14. **Styled Components** ensure fast and intuitive styling, allowing you to create stunning interfaces effortlessly.
  15. ![React Quiz App Template](./src/assets/images/Xeven-Quiz-App-Screenshots.png)
  16. ## React Quiz App's Theme Features
  17. Before I explain the technical aspects of the quiz app, let me share the wonderful features of the quiz app. You can get all these features in a template and mold them according to your choice.
  18. - Seamlessly switch between Light and Dark modes with just a single click from the top menu.
  19. - The user can pick a quiz topic on the first screen, like JavaScript, React, or General Knowledge.
  20. - There will be a timer running when the quiz starts. If the timer finishes, the quiz will be stopped, and the user will be asked to see the result.
  21. - The template also supports three types of questions, MCQs, True/False, and MAQs.
  22. - The template allows for adding code snippets in questions. You can easily assess the users' programming knowledge and skills.
  23. - The template allows you to create questions with images to enhance user engagement.
  24. - Each question has a score. For example, a difficult question has 10 marks, and an easier one has 5.
  25. - The result screen shows how many questions the user attempted, how much he scored, how long it took, and whether he passed or failed.
  26. - In result screen user can see which question had the right answer and which was wrong. The user can find the correct answer in case of a wrong answer.
  27. ## React Quiz App's Code Features
  28. - **TypeScript powered Components**: All components are TypeScript-built for enhanced development productivity with intelligent code completion and compile-time error checking.
  29. - **Easy Theme Customization**: The template provides easy theme management with IntelliSense support via Styled Components and Typescript. It allows you to customize the app's appearance without relying on hard-coded colors.
  30. - **Flexible Question Data Structure**: The template uses Javascript/TypeScript files to define quiz questions. This format provides a structured and flexible approach. The same format can also be used to fetch questions from an API if desired.
  31. - **Modular and Context Pattern**: The template follows a javascript modular and React Context pattern, promoting component reusability and maintainability.
  32. - **Custom Hooks for Logic Sharing**: The hook pattern lets you share logic across components. It also promotes code reuse and minimizes code clutter.
  33. - **Built with React Best Practices**: App follows industry-leading React practices. Our template ensures optimal structure, scalability, and maintainability.
  34. ![types of questions](./src/assets/images/3-types-of-questions.png)
  35. ## Xeven Quiz - ReactJS Quiz App Template Code Documentations
  36. This guide will walk you through the steps to start using and customizing the app according to your needs. The Xeven Quiz is designed to help you create interactive quizzes with various question types, including Multiple Choice Questions (MCQs), Multiple Answer Questions (MAQs), and True/False questions.
  37. ## Demo App
  38. To experience the Demo App, visit the link: https://xeven-quiz.vercel.app/
  39. ## **How to Start a Project**
  40. To start the project, follow these steps:
  41. 1. Clone the repo and navigate to the project directory via terminal.
  42. 2. Run the command **`npm install`** to download and install all the project dependencies.
  43. 3. Once the dependencies are installed, run the command **`npm start`** to start the development server.
  44. ### Folder Structure Explanation
  45. Understanding the folder structure is essential for working with the app. Here's an overview of the main folders:
  46. ![quiz-app-folder-structure.png](./src/assets/images/quiz-app-folder-structure.png)
  47. - **assets**: Contains all the app's assets, such as fonts, icons, and images
  48. - **components**: Contains all the components of app
  49. - **components/UI**: Contains reusable UI components of app
  50. - **context**: Includes a context for sharing logic across the app
  51. - **styles**: Contains styles and their configurations using Styled Components
  52. - **hooks**: Includes reusable hooks used in the app
  53. - **utils**: Contains Javascript helper functions
  54. - **data**: Contains quiz questions and quiz topic screens data
  55. - **types**: Contains TypeScript types used throughout the app
  56. - **config**: Imports all the icons, providing centralized access
  57. ### Components Architecture
  58. The **Xeven Quiz App** consists of 5 main screens/components that are displayed conditionally:
  59. 1. Splash Screen
  60. 2. Quiz Topics Screen
  61. 3. Quiz Details Screen
  62. 4. Questions Screen
  63. 5. Result Screen
  64. The screens are organized in the **`components`** folder since the app does not utilize routing. If a component is reusable and can be used in multiple places within the app (e.g., Button, ModalWrapper, and CodeSnippet), it is placed in the **`components/UI`** folder. On the other hand, if a component is screen-specific and separated just to make other components smaller and more manageable, it is placed in the relevant components folder. For example, the components `**QuizHeader**`, `**Question**`, and `**Answer**` are inside the **`QuestionScreen`** folder.
  65. ## How to customize the quiz layout and styling
  66. ### Changing the App Theme
  67. To change the theme of the app, follow these steps:
  68. 1. Open the **`styles/Themes`** file.
  69. 2. Modify the colors in the themes to customize the app's appearance.
  70. ### Changing the App Font
  71. To change the font of the app, follow these steps:
  72. 1. Go to **`assets`****`fonts`**.
  73. 2. Replace the current fonts (e.g., "anek-malayalam") with the fonts you want to use.
  74. 3. Go to **`fonts.module.css`** file ****and replace the font name and path with new font you added.
  75. 4. Go to the **`theme`** file and change the font name.
  76. 5. Go to the global styles and update the font in the **`body`** section.
  77. ### Modifying the Quiz Topic Screen or Adding New Categories
  78. To modify the Quiz Topics Screen or add new categories of topics/icons, follow these steps:
  79. 1. Open the **`data/quizTopics`** file.
  80. 2. Make changes to the titles, icons or add new topics (by adding new object in `quizTopics`) as needed.
  81. 3. Ensure that the title in the **`QuizTopic`** data match the topic of **`data/QuizQuestions`** folder.
  82. For example
  83. ```jsx
  84. export const quizTopics: QuizTopic[] = [
  85. {
  86. title: 'React', // match topic value with this line
  87. icon: <ReactIcon />,
  88. },
  89. {
  90. title: 'JavaScript', // match topic value with this line
  91. icon: <JavaScript />,
  92. },
  93. ....
  94. ]
  95. export const javascript: Topic = {
  96. topic: 'Javascript', // match value with topic key
  97. level: 'Beginner',
  98. totalQuestions: 14,
  99. .....
  100. }
  101. ```
  102. ### Adding a New Screen
  103. This app is designed with scalability in mind, allowing you to easily add new screens. Here's how you can add a new screen, such as a "Quiz Types" screen (where you can select quiz type for example individual question timer, with or without timer):
  104. **Step 1: Create a component**
  105. Create a new component called **`QuizType`** in the **`components`** folder.
  106. **Step 2: Update the Main component**
  107. Go to the main components file (**`Main/index.ts`**) and render the **`QuizType`** screen in the **`screenComponents`** section/object. Don't forget to add the screen name in the typescript **`screenTypes`** as well.
  108. ```jsx
  109. const screenComponents = {
  110. [ScreenTypes.SplashScreen]: <SplashScreen />,
  111. [ScreenTypes.QuizTopicsScreen]: <QuizTopicsScreen />,
  112. [ScreenTypes.QuizTypesScreen]: <QuizTypesScreen />, // new screen
  113. [ScreenTypes.QuizDetailsScreen]: <QuizDetailsScreen />,
  114. [ScreenTypes.QuestionScreen]: <QuestionScreen />,
  115. [ScreenTypes.ResultScreen]: <ResultScreen />,
  116. }
  117. ```
  118. If you have multiple conditions to show the screen, you can change the object to a switch or if-else statement. Here's an example using a switch statement:
  119. ```jsx
  120. import { useEffect } from 'react'
  121. import { useQuiz } from '../../context/QuizContext'
  122. import { ScreenTypes } from '../../types'
  123. import QuestionScreen from '../QuestionScreen'
  124. import QuizDetailsScreen from '../QuizDetailsScreen'
  125. import QuizTopicsScreen from '../QuizTopicsScreen'
  126. import ResultScreen from '../ResultScreen'
  127. import SplashScreen from '../SplashScreen'
  128. function Main() {
  129. const { currentScreen, setCurrentScreen } = useQuiz()
  130. useEffect(() => {
  131. setTimeout(() => {
  132. setCurrentScreen(ScreenTypes.QuizTopicsScreen)
  133. }, 1000)
  134. }, [])
  135. switch (currentScreen) {
  136. case ScreenTypes.SplashScreen:
  137. return <SplashScreen />
  138. case ScreenTypes.QuizTopicsScreen:
  139. return <QuizTopicsScreen />
  140. case ScreenTypes.QuizDetailsScreen:
  141. return <QuizDetailsScreen />
  142. case ScreenTypes.QuestionScreen:
  143. return <QuestionScreen />
  144. case ScreenTypes.ResultScreen:
  145. return <ResultScreen />
  146. default:
  147. return <SplashScreen />
  148. }
  149. }
  150. export default Main
  151. ```
  152. ### Adding Pictures/Images to Questions
  153. In addition to text questions, you can also include images or pictures to enhance your questions. To add an image to a question, follow these steps:
  154. **1. Upload the Image**
  155. Start by placing your image file in the **`src/assets/images`** folder within your project directory.
  156. **2. Import the Image**
  157. Import the image in the quiz category data where you want to show it. For more details see `src/data/QuizQuestions/generalKnowledge.ts`
  158. **3. Link the Image to Your Question**
  159. Within your question object, add an image key. Then, reference the image you imported in step 2 at the top of your question.
  160. ![add question with picture](./src/assets/images/add-images-to-questions.png)
  161. ### How to Add Code Snippets in Questions
  162. Just like images, each question supports a **`code`** key, which is conditionally shown only if the question contains a code snippet.
  163. ### How to format code snippet
  164. In the Xeven Quiz App, code snippets are pieces of code represented as text. To make them look nice and readable, we use an npm package called **`prismjs`**. This tool highlights the code with different colors so that it stands out and is easy to understand.
  165. To display code correctly, we need to pay attention to the spaces and how the code is structured, just like we do with the existing questions. This way, the code will appear neatly formatted and will be easier for users to read and comprehend.
  166. Here's an example image to illustrate the correct format for displaying code snippets:
  167. ![code snippet format](./src/assets/images/code-snippet-format.png)
  168. ### Implementing Different Types of Quiz Questions
  169. The Code Quiz App supports various types of quiz questions, including Multiple Choice Questions (MCQs), Multiple Answer Questions (MAQs), and True/False questions. To add different question types, you can modify the question components and their associated data structures. You can refer to the existing question formats in the **`data/QuizQuestions`** folder as examples when creating new questions.
  170. For example, if you want to create a Multiple Choice Question (MCQ), you need to set its **`type`** to **`MCQs`** in the question data. Similarly, for a Multiple Answer Question (MAQ), set the **`type`** to **`MAQs`**, and for a True/False question, set it to the appropriate type as well.
  171. **Remember:** For MAQs, users can select multiple answer options, while for MCQs and True/False questions, users can select only one option. Make sure to set the correct **`type`** to match the question's behavior accordingly.
  172. ### Important Note
  173. Before making the Code Quiz App your own, remember to customize the meta and title tags in the **`index.html`** file, as well as the logo, preview image, and favicon image in the **`public`** folder. This ensures that the app reflects your branding and identity.
  174. ## Upgrade to PRO version
  175. Discover the Premium Version! Elevate your experience with the same amazing features you have seen in [demo](https://xeven-quiz.vercel.app/) app.
  176. [Check it out now!](https://basit313.gumroad.com/l/react-quiz-app-template)
  177. ### Premium Version Highlights
  178. Almost all the features I have added in this GitHub open source repo.
  179. - Every time the quiz starts, the questions will be shuffled or randomized
  180. - Users can skip a question if they are unsure of the answer. They can return to it later and answer it before submitting the quiz.
  181. ## **Deploying the Quiz App to a Production Environment**
  182. To share your quiz app with the world, you need to deploy it on a server that supports single-page applications or the React ecosystem. Here are some popular options for deploying your app:
  183. 1. Digital Ocean
  184. 2. Vercel
  185. 3. Netlify
  186. 4. AWS Amplify
  187. Choose the one that best suits your needs and follow their deployment instructions to make your app accessible to users.
  188. ### Contact Me
  189. I hope this documentation helps you get started with the Xeven Quiz App. If you have any questions or feedback, please feel free to reach out to me at **[abdul_basit313@outlook.com](mailto:abdul_basit313@outlook.com)**. Happy quizzing!