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.

248 lines
13 KiB

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