Source

containers/Custom/QuizSingleScreen.ts

import {mapProps, compose} from "recompose";
import Quiz from "../QuizSingleScreen";
import withLoadQuiz from "../../components/hocs/withLoadQuiz";
import withActiveCallBacks from "../../navigators/react-navigation-addons/withActiveCallBacks";
import {withNavigation} from "../../components/hocs/withNavigation";
import PropTypes from "prop-types";

const buildProps = props => {
	const {parent, courseId, lessonId, topicId} = props;

	let parentId;

	switch (parent) {
		case "course":
			parentId = courseId;
			break;
		case "lesson":
			parentId = lessonId;
			break;
		case "topic":
			parentId = topicId;
			break;
		default:
			break;
	}

	return {
		...props,
		parentId
	};
};

/**
 * You can use this component to display your Quiz single screen in your custom screen.
 * @component
 * @example <caption> Display a quiz whose parent is a topic </caption>
 * //In custom_code/components/MyCustomScreen.js
 *
 * import React from 'react';
 * import { View } from 'react-native';
 * import externalCodeDependencies from "@src/externalCode/externalRepo/externalCodeDependencies";
 * import QuizSingleScreen from "@src/containers/Custom/QuizSingleScreen";
 *
 * const MyCustomScreen = (props) => {
 *
 *  const courseId = 162;
 *  const lessonId = 164;
 *  const topicId = 226;
 *  const quizId = 185;
 *
 *  return <View style={{ flex: 1, marginBottom: 80 }}>
 *    <QuizSingleScreen
 *      parent="topic"
 *      courseId={courseId}
 *      lessonId={lessonId}
 *      topicId={topicId}
 *      quizId={quizId}
 *    />
 *  </View>
 * }
 *
 *
 * export default MyCustomScreen;
 *
 * //In custom_code/index.js...
 *
 * ...
 *
 * import MyCustomScreen from "./components/MyCustomScreen";
 *
 * export const applyCustomCode = externalCodeSetup => {
 *
 *  externalCodeSetup.navigationApi.addNavigationRoute(
 *    "book",
 *    "BookScreen",
 *    MyCustomScreen,
 *    "All"
 *  );
 *  externalCodeSetup.navigationApi.addNavigationRoute(
 *    "book",
 *    "BookScreen",
 *    MyCustomScreen,
 *    "Main"
 *  );
 * }
 * @example <caption> Display a quiz whose parent is a lesson </caption>
 *
 * //In custom_code/components/MyCustomScreen.js
 * import React from 'react';
 * import { View } from 'react-native';
 * import externalCodeDependencies from "@src/externalCode/externalRepo/externalCodeDependencies";
 * import QuizSingleScreen from "@src/containers/Custom/QuizSingleScreen";
 *
 * const MyCustomScreen = (props) => {
 *
 *  const courseId = 41;
 *  const lessonId = 76;
 *  const quizId = 79;
 *
 *  return <View style={{ flex: 1, marginBottom: 80 }}>
 *    <QuizSingleScreen
 *      parent="lesson"
 *      courseId={courseId}
 *      lessonId={lessonId}
 *      quizId={quizId}
 *    />
 *  </View>
 * }
 *
 *
 * export default MyCustomScreen;
 *
 * //In custom_code/index.js...
 *
 * ...
 *
 * import MyCustomScreen from "./components/MyCustomScreen";
 *
 * export const applyCustomCode = externalCodeSetup => {
 *
 *  externalCodeSetup.navigationApi.addNavigationRoute(
 *    "book",
 *    "BookScreen",
 *    MyCustomScreen,
 *    "All"
 *  );
 *  externalCodeSetup.navigationApi.addNavigationRoute(
 *    "book",
 *    "BookScreen",
 *    MyCustomScreen,
 *    "Main"
 *  );
 * }
 *
 * @example <caption> Display a quiz whose parent is a course </caption>
 * //In custom_code/components/MyCustomScreen.js
 *
 * import React from 'react';
 * import { View } from 'react-native';
 * import QuizSingleScreen from "@src/containers/Custom/QuizSingleScreen";
 *
 * const MyCustomScreen = (props) => {
 *
 *  const courseId = 170;
 *  const quizId = 245;
 *
 *  return <View style={{ flex: 1, marginBottom: 80 }}>
 *    <QuizSingleScreen
 *      parent="course"
 *      courseId={courseId}
 *      quizId={quizId}
 *    />
 *  </View>
 * }
 *
 * export default MyCustomScreen;
 *
 * //In custom_code/index.js...
 *
 * ...
 *
 * import MyCustomScreen from "./components/MyCustomScreen";
 *
 * export const applyCustomCode = externalCodeSetup => {
 *
 *  externalCodeSetup.navigationApi.addNavigationRoute(
 *    "book",
 *    "BookScreen",
 *    MyCustomScreen,
 *    "All"
 *  );
 *  externalCodeSetup.navigationApi.addNavigationRoute(
 *    "book",
 *    "BookScreen",
 *    MyCustomScreen,
 *    "Main"
 *  );
 * }
 *
 */

const QuizSingleScreen = compose(
	mapProps(buildProps),
	withNavigation,
	withActiveCallBacks
)(Quiz);

export default withLoadQuiz(QuizSingleScreen);

QuizSingleScreen.propTypes = {
	/**
	 * The immediate parent of the quiz. Choose whether it is `course`, `lesson` or `topic`
	 * {String}
	 */
	parent: PropTypes.string.isRequired,
	/**
	 * The id of the course where the quiz belongs
	 * {Number}
	 */
	courseId: PropTypes.number.isRequired,
	/**
	 * The id of the lesson where the quiz belongs
	 * {Number}
	 */
	lessonId: PropTypes.number,
	/**
	 * The id of the topic where the quiz belongs
	 * {Number}
	 */
	topicId: PropTypes.number,
	/**
	 * The id of the quiz to display
	 * {Number}
	 */
	quizId: PropTypes.number,
	/**
	 * Use `true` to hide Prev and Next buttons
	 * {Boolean}
	 */
	hidePrevNext: PropTypes.bool,
	/**
	 * Use `true` to hide back button
	 * {Boolean}
	 */
	hideBackToCourse: PropTypes.bool,
	/**
	 * Use this to display your own loading component while the screen is loading
	 * {ReactComponent}
	 */
	LoadingComponent: PropTypes.elementType
};