Created
October 6, 2017 14:38
-
-
Save thecolorblue/1105e40a9b543a3813b3053e2f5b30c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function CourseCatalogBody({ gridOnly, gotoDetails, items, view, toggleCourse, purchaseCourses }) { | |
| if (view === 'table' && gridOnly != 'true') { | |
| return <CoursesTable items={items} gotoDetails={gotoDetails} toggleCourse={toggleCourse} purchaseCourses={purchaseCourses} />; | |
| } | |
| return <CoursesGrid items={items} gotoDetails={gotoDetails} />; | |
| } | |
| function factory(View, inject, dispatch) { | |
| return function (connect, state) { | |
| connect(state, (...args) => { | |
| return { | |
| ...inject(Dependencies), | |
| ...dispatch.apply(dispatch) | |
| } | |
| }) | |
| } | |
| } | |
| export default factory({ | |
| 'CourseCatalogBody': [ | |
| CourseCatalogBody, | |
| ({ courses: { CourseCard } }) => ({ CourseCard }), | |
| (dispatch, ownProps) => { | |
| dispatch({ type: 'COURSES_LOADED' }); | |
| return { | |
| gotoDetails: (id) => e => { | |
| // TODO: find a better way to redirect to details without a page load on purchaseCourses.aspx | |
| if (window.location.pathname === "/Custom/Pages/PurchaseCourses.aspx") { | |
| e.preventDefault(); | |
| dispatch(push(`#/details/${id}`)); | |
| } | |
| }, | |
| toggleCourse: item => e => { | |
| dispatch(toggleCourse(item)); | |
| }, | |
| purchaseCourses: e => { | |
| e.preventDefault(); | |
| dispatch(purchaseCourses()); | |
| } | |
| } | |
| } | |
| ] | |
| }) | |
| function find(name, state) { | |
| return connect(components[name], state); | |
| } | |
| const CourseGrid = find('CourseCatalogBody', ) | |
| map({ | |
| 'CourseCatalogBody': state => ({ items: state.items.list, view: state.settings.courseView }) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment