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.

205 lines
9.0 KiB

  1. # Xeven Quiz - ReactJS Quiz App Template Code Documentations
  2. 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.
  3. ## Demo App
  4. To experience the Demo App, visit the link: https://xeven-quiz.vercel.app/
  5. ## **How to Start a Project**
  6. To start the project, follow these steps:
  7. 1. Open the terminal and navigate to the project directory.
  8. 2. Run the command **`npm install`** to download and install all the project dependencies.
  9. 3. Once the dependencies are installed, run the command **`npm start`** to start the development server.
  10. ### Folder Structure Explanation
  11. Understanding the folder structure is essential for working with the app. Here's an overview of the main folders:
  12. ![quiz-app-folder-structure.png](./src/assets/images/quiz-app-folder-structure.png)
  13. - **assets**: Contains all the app's assets, such as fonts, icons, and images
  14. - **components**: Contains all the components of app
  15. - **components/UI**: Contains reusable UI components of app
  16. - **context**: Includes a context for sharing logic across the app
  17. - **styles**: Contains styles and their configurations using Styled Components
  18. - **hooks**: Includes reusable hooks used in the app
  19. - **utils**: Contains Javascript helper functions
  20. - **data**: Contains quiz questions and quiz topic screens data
  21. - **types**: Contains TypeScript types used throughout the app
  22. - **config**: Imports all the icons, providing centralized access
  23. ### Components Architecture
  24. The **Xeven Quiz App** consists of 5 main screens/components that are displayed conditionally:
  25. 1. Splash Screen
  26. 2. Quiz Topics Screen
  27. 3. Quiz Details Screen
  28. 4. Questions Screen
  29. 5. Result Screen
  30. 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.
  31. ## How to customize the quiz layout and styling
  32. ### **Changing the App Theme**
  33. To change the theme of the app, follow these steps:
  34. 1. Open the **`styles/Themes`** file.
  35. 2. Modify the colors in the themes to customize the app's appearance.
  36. ### Changing the App Font
  37. To change the font of the app, follow these steps:
  38. 1. Go to **`assets`****`fonts`**.
  39. 2. Replace the current fonts (e.g., "anek-malayalam") with the fonts you want to use.
  40. 3. Go to **`fonts.module.css`** file ****and replace the font name and path with new font you added.
  41. 4. Go to the **`theme`** file and change the font name.
  42. 5. Go to the global styles and update the font in the **`body`** section.
  43. ### **Modifying the Quiz Topic Screen or Adding New Categories**
  44. To modify the Quiz Topics Screen or add new categories of topics/icons, follow these steps:
  45. 1. Open the **`data/quizTopics`** file.
  46. 2. Make changes to the titles, icons or add new topics (by adding new object in `quizTopics`) as needed.
  47. 3. Ensure that the title in the **`QuizTopic`** data match the topic of **`data/QuizQuestions`** folder.
  48. For example
  49. ```jsx
  50. export const quizTopics: QuizTopic[] = [
  51. {
  52. title: 'React', // match topic value with this line
  53. icon: <ReactIcon />,
  54. },
  55. {
  56. title: 'JavaScript', // match topic value with this line
  57. icon: <JavaScript />,
  58. },
  59. ....
  60. ]
  61. export const javascript: Topic = {
  62. topic: 'Javascript', // match value with topic key
  63. level: 'Beginner',
  64. totalQuestions: 14,
  65. .....
  66. }
  67. ```
  68. ### Adding a New Screen
  69. 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):
  70. **Step 1: Create a component**
  71. Create a new component called **`QuizType`** in the **`components`** folder.
  72. **Step 2: Update the Main component**
  73. 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.
  74. ```jsx
  75. const screenComponents = {
  76. [ScreenTypes.SplashScreen]: <SplashScreen />,
  77. [ScreenTypes.QuizTopicsScreen]: <QuizTopicsScreen />,
  78. [ScreenTypes.QuizTypesScreen]: <QuizTypesScreen />, // new screen
  79. [ScreenTypes.QuizDetailsScreen]: <QuizDetailsScreen />,
  80. [ScreenTypes.QuestionScreen]: <QuestionScreen />,
  81. [ScreenTypes.ResultScreen]: <ResultScreen />,
  82. }
  83. ```
  84. 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:
  85. ```jsx
  86. import { useEffect } from 'react'
  87. import { useQuiz } from '../../context/QuizContext'
  88. import { ScreenTypes } from '../../types'
  89. import QuestionScreen from '../QuestionScreen'
  90. import QuizDetailsScreen from '../QuizDetailsScreen'
  91. import QuizTopicsScreen from '../QuizTopicsScreen'
  92. import ResultScreen from '../ResultScreen'
  93. import SplashScreen from '../SplashScreen'
  94. function Main() {
  95. const { currentScreen, setCurrentScreen } = useQuiz()
  96. useEffect(() => {
  97. setTimeout(() => {
  98. setCurrentScreen(ScreenTypes.QuizTopicsScreen)
  99. }, 1000)
  100. }, [])
  101. switch (currentScreen) {
  102. case ScreenTypes.SplashScreen:
  103. return <SplashScreen />
  104. case ScreenTypes.QuizTopicsScreen:
  105. return <QuizTopicsScreen />
  106. case ScreenTypes.QuizDetailsScreen:
  107. return <QuizDetailsScreen />
  108. case ScreenTypes.QuestionScreen:
  109. return <QuestionScreen />
  110. case ScreenTypes.ResultScreen:
  111. return <ResultScreen />
  112. default:
  113. return <SplashScreen />
  114. }
  115. }
  116. export default Main
  117. ```
  118. ### **How to Add Code Snippets in Questions**
  119. Each question supports a **`code`** key, which is conditionally shown only if the question contains a code snippet.
  120. ### How to format code snippet
  121. 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.
  122. 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.
  123. Here's an example image to illustrate the correct format for displaying code snippets:
  124. ![code-snippet-format.png](./src/assets/images/code-snippet-format.png)
  125. ### **Implementing Different Types of Quiz Questions**
  126. 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.
  127. 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.
  128. **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.
  129. ### **Important Note**
  130. 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.
  131. ## **Deploying the Quiz App to a Production Environment**
  132. 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:
  133. 1. Digital Ocean
  134. 2. Vercel
  135. 3. Netlify
  136. 4. AWS Amplify
  137. Choose the one that best suits your needs and follow their deployment instructions to make your app accessible to users.
  138. ### What to expect in next update?
  139. The next app update, scheduled for September 2023, will bring exciting new features and improvements:
  140. 1. Dark mode support.
  141. 2. Image support in Quiz Questions.
  142. 3. Faster Typography with Typography Styled components
  143. 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!