Source

containers/Custom/CourseCategoriesScreen.ts

import {mapProps, compose} from "recompose";
import CourseCategoriesFilter from "../../components/Courses/CourseCategoriesFilter";
import withLearndashLabels from "../../components/hocs/withLearnDashTranslations";

import withActiveCallBacks from "../../navigators/react-navigation-addons/withActiveCallBacks";
import {withNavigation} from "../../components/hocs/withNavigation";
import PropTypes from "prop-types";

const buildFilterProps = props => ({
	navigation: props.navigation,
	screenTitle: props.route.params?.item?.label || props.labels.courses,
	...props
});

/**
 * You can use this component to display your course categories screen in your custom screen.
 * @component
 * @example <caption> Display course categories screen with a component to navigate to a featured course </caption>
 *
 * //In custom_code/components/MyCustomScreen.js...
 * import React from "react";
 * import {View, Button} from "react-native";
 * import {useSelector} from "react-redux";
 * import {CommonActions} from "@react-navigation/native";
 *
 * import CourseCategoriesScreen from "@src/containers/Custom/CourseCategoriesScreen";
 * import {useScreenProps} from "@src/navigators/v5/ScreenPropsProvider";
 *
 * const MyCustomScreen = props => {
 *     const {colors} = useScreenProps(["colors"]);
 *     const state = useSelector(state => state);
 *     const featuredCourseId = 49;
 *
 *     const goToFeaturedCourse = courseId => {
 *         const featuredCourse = state.coursesCache.byId.get(
 *             courseId ? courseId.toString() : ""
 *         );
 *
 *         //Navigate to featured course
 *         props.navigation.dispatch(
 *             CommonActions.navigate({
 *                 name: "CoursesSingleScreen",
 *                 params: {
 *                     id: featuredCourse.id,
 *                     featuredCourse
 *                 },
 *                 key: featuredCourse.id.toString()
 *             })
 *         );
 *     };
 *
 *     return (
 *         <View style={{flex: 1}}>
 *             <View style={{flex: 0.8}}>
 *                 <CourseCategoriesScreen
 *                     {...props}
 *                     screenTitle="Course Categories"
 *                     hideFilters={true}
 *                     headerHeight={150}
 *                     hideNavigationHeader={true}
 *                 />
 *             </View>
 *
 *             <View style={{flex: 0.2, backgroundColor: colors.bodyFrontBg}}>
 *                 <Button
 *                     title="Go to featured course"
 *                     onPress={() => goToFeaturedCourse(featuredCourseId)}
 *                 />
 *             </View>
 *         </View>
 *     );
 * };
 *
 *
 * export default MyCustomScreen;
 *
 *
 * //In custom_code/index.js...
 *
 * ...
 *
 * import MyCustomScreen from "./components/MyCustomScreen";
 *
 * export const applyCustomCode = externalCodeSetup => {
 *   externalCodeSetup.navigationApi.replaceScreenComponent("courses_category", MyCustomScreen);
 * }
 */
export const CourseCategoriesScreen = compose(
	withLearndashLabels,
	withNavigation,
	withActiveCallBacks,
	mapProps(buildFilterProps)
)(CourseCategoriesFilter);

CourseCategoriesScreen.propTypes = {
	/**
	 * List screen title. Default comes from translation files in BuddyBoss site
	 * {String}
	 */
	screenTitle: PropTypes.string,
	/**
	 * Use `true` to hide title of the screen
	 * {Boolean}
	 */
	hideTitle: PropTypes.bool,
	/**
	 * Use `true` to hide filters in the screen
	 * {Boolean}
	 */
	hideFilters: PropTypes.bool,
	/**
	 * Use `true` to hide the screen title container when scrolling
	 * {Boolean}
	 */
	hideNavigationHeader: PropTypes.bool,
	/**
	 * Define header height
	 * {Number}
	 */
	headerHeight: PropTypes.number
};

export default CourseCategoriesScreen;