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.

239 lines
12 KiB

  1. ![React Quiz App Template Cover Image](./src/assets/images/Xeven-Quiz-ReactJS-Quiz-App-Template.jpg)
  2. # Xeven Quiz - ReactJS Quiz App Template
  3. With **Xeven Quiz**, you don't have to spend hours coding from scratch. Our 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. Xeven Quiz helps you follow industry best practices and coding conventions as a beginner.
  4. As a beginner developer, a quiz app is a common project. But without guidance, this simple project can become difficult. 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.
  5. 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.
  6. ### Powerful Tech Stack
  7. - Reactjs
  8. - Typescript
  9. - Styled components
  10. With **ReactJS** at its core, it lets you design dynamic interfaces that automatically update and respond to user interactions.
  11. **TypeScript** brings enhanced development productivity through static typing and intelligent tooling.
  12. **Styled Components** ensure fast and intuitive styling, allowing you to create stunning interfaces effortlessly.
  13. ## React Quiz App's Theme Features
  14. Before I explain the technical aspects of the quiz app, let me share the wonderful features of the quiz app that is available in demo GitHub version. You can get all these features in a template and mold them according to your choice.
  15. - Each time the quiz starts, questions will be shuffled or randomized.
  16. - 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.
  17. - Each question has a score. For example, a difficult question has 10 marks, and an easier one has 5.
  18. - The template also supports three types of questions, MCQs, True/False, and MAQs.
  19. - The result screen shows how many questions the user attempted, how much he scored, how long it took, and whether he passed or failed.
  20. - 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.
  21. ## React Quiz App's Code Features
  22. - **TypeScript powered Components:** All components are TypeScript-built for enhanced development productivity with intelligent code completion and compile-time error checking.
  23. - **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.
  24. - **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.
  25. - **Modular and Context Pattern:** The template follows a javascript modular and React Context pattern, promoting component reusability and maintainability.
  26. - **Custom Hooks for Logic Sharing:** The hook pattern lets you share logic across components. It also promotes code reuse and minimizes code clutter.
  27. - **Built with React Best Practices:** App follows industry-leading React practices. Our template ensures optimal structure, scalability, and maintainability.
  28. ## Xeven Quiz - ReactJS Quiz App Template Code Documentations
  29. 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.
  30. ## Demo App
  31. To experience the Demo App, visit the link: https://xeven-quiz.vercel.app/
  32. ## **How to Start a Project**
  33. To start the project, follow these steps:
  34. 1. Clone the repo and navigate to the project directory via terminal.
  35. 2. Run the command **`npm install`** to download and install all the project dependencies.
  36. 3. Once the dependencies are installed, run the command **`npm start`** to start the development server.
  37. ### Folder Structure Explanation
  38. Understanding the folder structure is essential for working with the app. Here's an overview of the main folders:
  39. ![quiz-app-folder-structure.png](./src/assets/images/quiz-app-folder-structure.png)
  40. - **assets**: Contains all the app's assets, such as fonts, icons, and images
  41. - **components**: Contains all the components of app
  42. - **components/UI**: Contains reusable UI components of app
  43. - **context**: Includes a context for sharing logic across the app
  44. - **styles**: Contains styles and their configurations using Styled Components
  45. - **hooks**: Includes reusable hooks used in the app
  46. - **utils**: Contains Javascript helper functions
  47. - **data**: Contains quiz questions and quiz topic screens data
  48. - **types**: Contains TypeScript types used throughout the app
  49. - **config**: Imports all the icons, providing centralized access
  50. ### Components Architecture
  51. The **Xeven Quiz App** consists of 4 main screens/components that are displayed conditionally (in light version):
  52. 1. Splash Screen
  53. 2. Quiz Details Screen
  54. 3. Questions Screen
  55. 4. Result Screen
  56. 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.
  57. ## How to customize the quiz layout and styling
  58. ### **Changing the App Theme**
  59. To change the theme of the app, follow these steps:
  60. 1. Open the **`styles/Themes`** file.
  61. 2. Modify the colors in the themes to customize the app's appearance.
  62. ### Changing the App Font
  63. To change the font of the app, follow these steps:
  64. 1. Go to **`assets`****`fonts`**.
  65. 2. Replace the current fonts (e.g., "anek-malayalam") with the fonts you want to use.
  66. 3. Go to **`fonts.module.css`** file ****and replace the font name and path with new font you added.
  67. 4. Go to the **`theme`** file and change the font name.
  68. 5. Go to the global styles and update the font in the **`body`** section.
  69. ### **Modifying the Quiz Topic Screen or Adding New Categories**
  70. To modify the Quiz Topics Screen or add new categories of topics/icons, follow these steps:
  71. 1. Open the **`data/quizTopics`** file.
  72. 2. Make changes to the titles, icons or add new topics (by adding new object in `quizTopics`) as needed.
  73. 3. Ensure that the title in the **`QuizTopic`** data match the topic of **`data/QuizQuestions`** folder.
  74. For example
  75. ```jsx
  76. export const quizTopics: QuizTopic[] = [
  77. {
  78. title: 'React', // match topic value with this line
  79. icon: <ReactIcon />,
  80. },
  81. {
  82. title: 'JavaScript', // match topic value with this line
  83. icon: <JavaScript />,
  84. },
  85. ....
  86. ]
  87. export const javascript: Topic = {
  88. topic: 'Javascript', // match value with topic key
  89. level: 'Beginner',
  90. totalQuestions: 14,
  91. .....
  92. }
  93. ```
  94. ### Adding a New Screen
  95. 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):
  96. **Step 1: Create a component**
  97. Create a new component called **`QuizType`** in the **`components`** folder.
  98. **Step 2: Update the Main component**
  99. 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.
  100. ```jsx
  101. const screenComponents = {
  102. [ScreenTypes.SplashScreen]: <SplashScreen />,
  103. [ScreenTypes.QuizTopicsScreen]: <QuizTopicsScreen />,
  104. [ScreenTypes.QuizTypesScreen]: <QuizTypesScreen />, // new screen
  105. [ScreenTypes.QuizDetailsScreen]: <QuizDetailsScreen />,
  106. [ScreenTypes.QuestionScreen]: <QuestionScreen />,
  107. [ScreenTypes.ResultScreen]: <ResultScreen />,
  108. }
  109. ```
  110. 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:
  111. ```jsx
  112. import { useEffect } from 'react'
  113. import { useQuiz } from '../../context/QuizContext'
  114. import { ScreenTypes } from '../../types'
  115. import QuestionScreen from '../QuestionScreen'
  116. import QuizDetailsScreen from '../QuizDetailsScreen'
  117. import QuizTopicsScreen from '../QuizTopicsScreen'
  118. import ResultScreen from '../ResultScreen'
  119. import SplashScreen from '../SplashScreen'
  120. function Main() {
  121. const { currentScreen, setCurrentScreen } = useQuiz()
  122. useEffect(() => {
  123. setTimeout(() => {
  124. setCurrentScreen(ScreenTypes.QuizTopicsScreen)
  125. }, 1000)
  126. }, [])
  127. switch (currentScreen) {
  128. case ScreenTypes.SplashScreen:
  129. return <SplashScreen />
  130. case ScreenTypes.QuizTopicsScreen:
  131. return <QuizTopicsScreen />
  132. case ScreenTypes.QuizDetailsScreen:
  133. return <QuizDetailsScreen />
  134. case ScreenTypes.QuestionScreen:
  135. return <QuestionScreen />
  136. case ScreenTypes.ResultScreen:
  137. return <ResultScreen />
  138. default:
  139. return <SplashScreen />
  140. }
  141. }
  142. export default Main
  143. ```
  144. ### Implementing Different Types of Quiz Questions
  145. 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.
  146. 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.
  147. **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.
  148. ### Important Note
  149. 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.
  150. ## Upgrade to PRO version
  151. Discover the Premium Version! Elevate your experience with the same amazing features you have seen in [demo](https://xeven-quiz.vercel.app/) app.
  152. [Check it out now!](https://basit313.gumroad.com/l/react-quiz-app-template)
  153. ### Premium Version Highlights
  154. - Elevate user experience by seamlessly toggling between light and dark modes with a single click from the top menu.
  155. - The user can pick a quiz topic on the first screen, like JavaScript, React, or Python.
  156. - 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.
  157. - The PRO version also allows for adding code snippets in questions. You can easily assess the users' programming knowledge and skills.
  158. ## **Deploying the Quiz App to a Production Environment**
  159. 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:
  160. 1. Digital Ocean
  161. 2. Vercel
  162. 3. Netlify
  163. 4. AWS Amplify
  164. Choose the one that best suits your needs and follow their deployment instructions to make your app accessible to users.
  165. ### Contact Me
  166. 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!