1- import React , { Component } from "react" ;
2- import { connect } from "react-redux" ;
3- import utils from "../utils" ;
4- import { Dimmer , Icon , Loader , Pagination } from "semantic-ui-react" ;
5- import { Row , Col } from "./Grid" ;
6- import CourseSearchResultItem from "../containers/CourseSearchResultItem" ;
7- import Div from "../containers/Div" ;
8- import PropTypes from "prop-types" ;
9- import * as _ from "lodash" ;
10- import { useNavigate } from "react-router-dom" ;
11- import { stringify } from "qs" ;
12-
13- class CourseSearchResults extends Component {
14- static propTypes = {
15- courseFilterParams : PropTypes . object ,
16- } ;
1+ import React , { Component } from 'react' ;
2+ import { connect , ConnectedProps } from 'react-redux' ;
3+ import utils from '../utils' ;
4+ import { RootState , CourseFilterParams } from '../types' ;
5+ import { Dimmer , Icon , Loader , Pagination } from 'semantic-ui-react' ;
6+ import { Row , Col } from './Grid' ;
7+ import CourseSearchResultItem from '../containers/CourseSearchResultItem' ;
8+ import Div from '../containers/Div' ;
9+ import * as _ from 'lodash' ;
10+ import { useNavigate } from 'react-router-dom' ;
11+ import { stringify } from 'qs' ;
12+
13+ interface CourseSearchResultsProps {
14+ courseFilterParams : CourseFilterParams ;
15+ navigate : ( path : string ) => void ;
16+ search ?: any ;
17+ actions ?: any ;
18+ }
1719
18- componentDidUpdate = ( prevProps ) => {
20+ class CourseSearchResults extends Component < CourseSearchResultsProps > {
21+ componentDidUpdate = ( prevProps : CourseSearchResultsProps ) => {
1922 const { actions, courseFilterParams } = this . props ;
2023
2124 if ( ! _ . isEqual ( courseFilterParams , prevProps . courseFilterParams ) ) {
2225 actions . fetchCourseSearch ( courseFilterParams , courseFilterParams . page ) ;
2326 }
2427 } ;
2528
26- onPageChange = ( event , data ) => {
29+ onPageChange = ( event : any , data : { activePage : number } ) => {
2730 const { activePage } = data ;
2831 const { courseFilterParams, navigate } = this . props ;
2932 const params = {
@@ -102,7 +105,7 @@ class CourseSearchResults extends Component {
102105 } ;
103106}
104107
105- function mapStateToProps ( state ) {
108+ function mapStateToProps ( state : RootState ) {
106109 const { searchQuery, courseFilterParams } = state . app ;
107110 const { page } = courseFilterParams ;
108111
@@ -121,14 +124,12 @@ function mapStateToProps(state) {
121124}
122125
123126// HOC to inject navigate as prop
124- function withNavigate ( Component ) {
125- return function ComponentWithNavigate ( props ) {
127+ function withNavigate ( Component : React . ComponentType < any > ) {
128+ return function ComponentWithNavigate ( props : any ) {
126129 const navigate = useNavigate ( ) ;
127130 return < Component { ...props } navigate = { navigate } /> ;
128131 } ;
129132}
130133
131- export default connect (
132- mapStateToProps ,
133- utils . mapDispatchToProps
134- ) ( withNavigate ( CourseSearchResults ) ) ;
134+ const connector = connect ( mapStateToProps , utils . mapDispatchToProps ) ;
135+ export default connector ( withNavigate ( CourseSearchResults ) ) ;
0 commit comments