Source

containers/Custom/QuizSingleScreen.ts

  1. import {mapProps, compose} from "recompose";
  2. import Quiz from "../QuizSingleScreen";
  3. import withLoadQuiz from "../../components/hocs/withLoadQuiz";
  4. import withActiveCallBacks from "../../navigators/react-navigation-addons/withActiveCallBacks";
  5. import {withNavigation} from "../../components/hocs/withNavigation";
  6. import PropTypes from "prop-types";
  7. const buildProps = props => {
  8. const {parent, courseId, lessonId, topicId} = props;
  9. let parentId;
  10. switch (parent) {
  11. case "course":
  12. parentId = courseId;
  13. break;
  14. case "lesson":
  15. parentId = lessonId;
  16. break;
  17. case "topic":
  18. parentId = topicId;
  19. break;
  20. default:
  21. break;
  22. }
  23. return {
  24. ...props,
  25. parentId
  26. };
  27. };
  28. /**
  29. * You can use this component to display your Quiz single screen in your custom screen.
  30. * @component
  31. * @example <caption> Display a quiz whose parent is a topic </caption>
  32. * //In custom_code/components/MyCustomScreen.js
  33. *
  34. * import React from 'react';
  35. * import { View } from 'react-native';
  36. * import externalCodeDependencies from "@src/externalCode/externalRepo/externalCodeDependencies";
  37. * import QuizSingleScreen from "@src/containers/Custom/QuizSingleScreen";
  38. *
  39. * const MyCustomScreen = (props) => {
  40. *
  41. * const courseId = 162;
  42. * const lessonId = 164;
  43. * const topicId = 226;
  44. * const quizId = 185;
  45. *
  46. * return <View style={{ flex: 1, marginBottom: 80 }}>
  47. * <QuizSingleScreen
  48. * parent="topic"
  49. * courseId={courseId}
  50. * lessonId={lessonId}
  51. * topicId={topicId}
  52. * quizId={quizId}
  53. * />
  54. * </View>
  55. * }
  56. *
  57. *
  58. * export default MyCustomScreen;
  59. *
  60. * //In custom_code/index.js...
  61. *
  62. * ...
  63. *
  64. * import MyCustomScreen from "./components/MyCustomScreen";
  65. *
  66. * export const applyCustomCode = externalCodeSetup => {
  67. *
  68. * externalCodeSetup.navigationApi.addNavigationRoute(
  69. * "book",
  70. * "BookScreen",
  71. * MyCustomScreen,
  72. * "All"
  73. * );
  74. * externalCodeSetup.navigationApi.addNavigationRoute(
  75. * "book",
  76. * "BookScreen",
  77. * MyCustomScreen,
  78. * "Main"
  79. * );
  80. * }
  81. * @example <caption> Display a quiz whose parent is a lesson </caption>
  82. *
  83. * //In custom_code/components/MyCustomScreen.js
  84. * import React from 'react';
  85. * import { View } from 'react-native';
  86. * import externalCodeDependencies from "@src/externalCode/externalRepo/externalCodeDependencies";
  87. * import QuizSingleScreen from "@src/containers/Custom/QuizSingleScreen";
  88. *
  89. * const MyCustomScreen = (props) => {
  90. *
  91. * const courseId = 41;
  92. * const lessonId = 76;
  93. * const quizId = 79;
  94. *
  95. * return <View style={{ flex: 1, marginBottom: 80 }}>
  96. * <QuizSingleScreen
  97. * parent="lesson"
  98. * courseId={courseId}
  99. * lessonId={lessonId}
  100. * quizId={quizId}
  101. * />
  102. * </View>
  103. * }
  104. *
  105. *
  106. * export default MyCustomScreen;
  107. *
  108. * //In custom_code/index.js...
  109. *
  110. * ...
  111. *
  112. * import MyCustomScreen from "./components/MyCustomScreen";
  113. *
  114. * export const applyCustomCode = externalCodeSetup => {
  115. *
  116. * externalCodeSetup.navigationApi.addNavigationRoute(
  117. * "book",
  118. * "BookScreen",
  119. * MyCustomScreen,
  120. * "All"
  121. * );
  122. * externalCodeSetup.navigationApi.addNavigationRoute(
  123. * "book",
  124. * "BookScreen",
  125. * MyCustomScreen,
  126. * "Main"
  127. * );
  128. * }
  129. *
  130. * @example <caption> Display a quiz whose parent is a course </caption>
  131. * //In custom_code/components/MyCustomScreen.js
  132. *
  133. * import React from 'react';
  134. * import { View } from 'react-native';
  135. * import QuizSingleScreen from "@src/containers/Custom/QuizSingleScreen";
  136. *
  137. * const MyCustomScreen = (props) => {
  138. *
  139. * const courseId = 170;
  140. * const quizId = 245;
  141. *
  142. * return <View style={{ flex: 1, marginBottom: 80 }}>
  143. * <QuizSingleScreen
  144. * parent="course"
  145. * courseId={courseId}
  146. * quizId={quizId}
  147. * />
  148. * </View>
  149. * }
  150. *
  151. * export default MyCustomScreen;
  152. *
  153. * //In custom_code/index.js...
  154. *
  155. * ...
  156. *
  157. * import MyCustomScreen from "./components/MyCustomScreen";
  158. *
  159. * export const applyCustomCode = externalCodeSetup => {
  160. *
  161. * externalCodeSetup.navigationApi.addNavigationRoute(
  162. * "book",
  163. * "BookScreen",
  164. * MyCustomScreen,
  165. * "All"
  166. * );
  167. * externalCodeSetup.navigationApi.addNavigationRoute(
  168. * "book",
  169. * "BookScreen",
  170. * MyCustomScreen,
  171. * "Main"
  172. * );
  173. * }
  174. *
  175. */
  176. const QuizSingleScreen = compose(
  177. mapProps(buildProps),
  178. withNavigation,
  179. withActiveCallBacks
  180. )(Quiz);
  181. export default withLoadQuiz(QuizSingleScreen);
  182. QuizSingleScreen.propTypes = {
  183. /**
  184. * The immediate parent of the quiz. Choose whether it is `course`, `lesson` or `topic`
  185. * {String}
  186. */
  187. parent: PropTypes.string.isRequired,
  188. /**
  189. * The id of the course where the quiz belongs
  190. * {Number}
  191. */
  192. courseId: PropTypes.number.isRequired,
  193. /**
  194. * The id of the lesson where the quiz belongs
  195. * {Number}
  196. */
  197. lessonId: PropTypes.number,
  198. /**
  199. * The id of the topic where the quiz belongs
  200. * {Number}
  201. */
  202. topicId: PropTypes.number,
  203. /**
  204. * The id of the quiz to display
  205. * {Number}
  206. */
  207. quizId: PropTypes.number,
  208. /**
  209. * Use `true` to hide Prev and Next buttons
  210. * {Boolean}
  211. */
  212. hidePrevNext: PropTypes.bool,
  213. /**
  214. * Use `true` to hide back button
  215. * {Boolean}
  216. */
  217. hideBackToCourse: PropTypes.bool,
  218. /**
  219. * Use this to display your own loading component while the screen is loading
  220. * {ReactComponent}
  221. */
  222. LoadingComponent: PropTypes.elementType
  223. };