Source

containers/Custom/CourseCategoriesScreen.ts

  1. import {mapProps, compose} from "recompose";
  2. import CourseCategoriesFilter from "../../components/Courses/CourseCategoriesFilter";
  3. import withLearndashLabels from "../../components/hocs/withLearnDashTranslations";
  4. import withActiveCallBacks from "../../navigators/react-navigation-addons/withActiveCallBacks";
  5. import {withNavigation} from "../../components/hocs/withNavigation";
  6. import PropTypes from "prop-types";
  7. const buildFilterProps = props => ({
  8. navigation: props.navigation,
  9. screenTitle: props.route.params?.item?.label || props.labels.courses,
  10. ...props
  11. });
  12. /**
  13. * You can use this component to display your course categories screen in your custom screen.
  14. * @component
  15. * @example <caption> Display course categories screen with a component to navigate to a featured course </caption>
  16. *
  17. * //In custom_code/components/MyCustomScreen.js...
  18. * import React from "react";
  19. * import {View, Button} from "react-native";
  20. * import {useSelector} from "react-redux";
  21. * import {CommonActions} from "@react-navigation/native";
  22. *
  23. * import CourseCategoriesScreen from "@src/containers/Custom/CourseCategoriesScreen";
  24. * import {useScreenProps} from "@src/navigators/v5/ScreenPropsProvider";
  25. *
  26. * const MyCustomScreen = props => {
  27. * const {colors} = useScreenProps(["colors"]);
  28. * const state = useSelector(state => state);
  29. * const featuredCourseId = 49;
  30. *
  31. * const goToFeaturedCourse = courseId => {
  32. * const featuredCourse = state.coursesCache.byId.get(
  33. * courseId ? courseId.toString() : ""
  34. * );
  35. *
  36. * //Navigate to featured course
  37. * props.navigation.dispatch(
  38. * CommonActions.navigate({
  39. * name: "CoursesSingleScreen",
  40. * params: {
  41. * id: featuredCourse.id,
  42. * featuredCourse
  43. * },
  44. * key: featuredCourse.id.toString()
  45. * })
  46. * );
  47. * };
  48. *
  49. * return (
  50. * <View style={{flex: 1}}>
  51. * <View style={{flex: 0.8}}>
  52. * <CourseCategoriesScreen
  53. * {...props}
  54. * screenTitle="Course Categories"
  55. * hideFilters={true}
  56. * headerHeight={150}
  57. * hideNavigationHeader={true}
  58. * />
  59. * </View>
  60. *
  61. * <View style={{flex: 0.2, backgroundColor: colors.bodyFrontBg}}>
  62. * <Button
  63. * title="Go to featured course"
  64. * onPress={() => goToFeaturedCourse(featuredCourseId)}
  65. * />
  66. * </View>
  67. * </View>
  68. * );
  69. * };
  70. *
  71. *
  72. * export default MyCustomScreen;
  73. *
  74. *
  75. * //In custom_code/index.js...
  76. *
  77. * ...
  78. *
  79. * import MyCustomScreen from "./components/MyCustomScreen";
  80. *
  81. * export const applyCustomCode = externalCodeSetup => {
  82. * externalCodeSetup.navigationApi.replaceScreenComponent("courses_category", MyCustomScreen);
  83. * }
  84. */
  85. export const CourseCategoriesScreen = compose(
  86. withLearndashLabels,
  87. withNavigation,
  88. withActiveCallBacks,
  89. mapProps(buildFilterProps)
  90. )(CourseCategoriesFilter);
  91. CourseCategoriesScreen.propTypes = {
  92. /**
  93. * List screen title. Default comes from translation files in BuddyBoss site
  94. * {String}
  95. */
  96. screenTitle: PropTypes.string,
  97. /**
  98. * Use `true` to hide title of the screen
  99. * {Boolean}
  100. */
  101. hideTitle: PropTypes.bool,
  102. /**
  103. * Use `true` to hide filters in the screen
  104. * {Boolean}
  105. */
  106. hideFilters: PropTypes.bool,
  107. /**
  108. * Use `true` to hide the screen title container when scrolling
  109. * {Boolean}
  110. */
  111. hideNavigationHeader: PropTypes.bool,
  112. /**
  113. * Define header height
  114. * {Number}
  115. */
  116. headerHeight: PropTypes.number
  117. };
  118. export default CourseCategoriesScreen;