@@ -7,6 +7,7 @@ import { push } from 'react-router-redux';
77import Helmet from 'react-helmet' ;
88import ReactPaginate from 'react-paginate' ;
99import { FormattedHTMLMessage } from 'react-intl' ;
10+ import IndexHeader from 'components/IndexHeader' ;
1011
1112import Verse from 'components/Verse' ;
1213import Loader from 'quran-components/lib/Loader' ;
@@ -17,23 +18,20 @@ import LocaleFormattedMessage from 'components/LocaleFormattedMessage';
1718
1819import { verseType , optionsType } from 'types' ;
1920
20- import Header from './Header' ;
21-
2221const style = require ( './style.scss' ) ;
2322
2423class Search extends Component {
2524 static propTypes = {
2625 isErrored : PropTypes . bool ,
2726 isLoading : PropTypes . bool ,
28- total : PropTypes . number ,
29- page : PropTypes . number ,
30- size : PropTypes . number ,
31- from : PropTypes . number ,
27+ totalCount : PropTypes . number ,
28+ totalPages : PropTypes . number ,
29+ currentPage : PropTypes . number ,
30+ perPage : PropTypes . number ,
3231 query : PropTypes . string ,
33- results : PropTypes . array , // eslint-disable-line
34- verses : PropTypes . objectOf ( verseType ) ,
32+ results : PropTypes . arrayOf ( verseType ) , // eslint-disable-line
3533 push : PropTypes . func . isRequired ,
36- location : PropTypes . shape ( {
34+ location : PropTypes . shape ( { // eslint-disable-line
3735 q : PropTypes . string ,
3836 p : PropTypes . string
3937 } ) ,
@@ -49,10 +47,10 @@ class Search extends Component {
4947 } ;
5048
5149 handlePageChange = ( payload ) => {
52- const { push, query, page } = this . props ; // eslint-disable-line no-shadow
50+ const { push, query, currentPage } = this . props ; // eslint-disable-line no-shadow
5351 const selectedPage = payload . selected + 1 ;
5452
55- if ( page !== selectedPage ) {
53+ if ( currentPage !== selectedPage ) {
5654 this . context . metrics . track (
5755 'Search' ,
5856 { action : 'paginate' , label : `${ query } - ${ selectedPage } ` }
@@ -68,13 +66,12 @@ class Search extends Component {
6866 }
6967
7068 renderStatsBar ( ) {
71- const { total, size, page, from, query } = this . props ;
72- const values = { from : 2 , to : ( from + size ) - 1 , total : 10 , query } ;
73-
74-
75- if ( total ) {
76- const pageNum = Math . ceil ( total / size ) ;
69+ const { totalCount, totalPages, currentPage, query, perPage } = this . props ;
70+ const from = Math . max ( ...[ ( currentPage - 1 ) * perPage , 1 ] ) ;
71+ const to = Math . min ( ...[ currentPage * perPage , totalCount ] ) ;
72+ const values = { from, to, query, total : totalCount } ;
7773
74+ if ( totalPages ) {
7875 return (
7976 < div className = { style . header } >
8077 < div className = "container" >
@@ -99,16 +96,17 @@ class Search extends Component {
9996 </ span >
10097 }
10198 breakLabel = { < a href = "" > ...</ a > }
102- pageNum = { pageNum }
99+ pageNum = { currentPage }
103100 marginPagesDisplayed = { 2 }
104101 pageRangeDisplayed = { 5 }
105- initialSelected = { page - 1 }
106- forceSelected = { page - 1 }
102+ initialSelected = { currentPage }
103+ forceSelected = { currentPage }
107104 onPageChange = { this . handlePageChange }
108105 containerClassName = "pagination"
109106 subContainerClassName = "pages pagination"
110- pageLinkClassName = "pointer: "
107+ pageLinkClassName = "pointer"
111108 activeClass = { style . active }
109+ pageCount = { totalPages }
112110 />
113111 </ div >
114112 </ div >
@@ -121,9 +119,9 @@ class Search extends Component {
121119 }
122120
123121 renderBody ( ) {
124- const { location , isErrored, isLoading, results, options, verses } = this . props ;
122+ const { isErrored, isLoading, results, options, query } = this . props ;
125123
126- if ( ! location . q ) {
124+ if ( ! query ) {
127125 return (
128126 < h3 className = "text-center" style = { { padding : '15%' } } >
129127 < LocaleFormattedMessage id = "search.nothing" defaultMessage = "No search query." />
@@ -153,9 +151,9 @@ class Search extends Component {
153151
154152 return results . map ( result => (
155153 < Verse
156- verse = { verses [ result . verse ] }
154+ verse = { result }
157155 match = { result . match }
158- key = { result . verse }
156+ key = { result . verseKey }
159157 tooltip = { options . tooltip }
160158 isSearched
161159 />
@@ -174,7 +172,7 @@ class Search extends Component {
174172 .text-translation{font-size: ${ options . fontSize . translation } rem;}`
175173 } ] }
176174 />
177- < Header />
175+ < IndexHeader />
178176 { this . renderStatsBar ( ) }
179177 < div className = "container surah-list" >
180178 < div className = "row" >
@@ -191,26 +189,25 @@ class Search extends Component {
191189const AsyncSearch = asyncConnect ( [ {
192190 promise ( { store : { dispatch } , location } ) {
193191 if ( __CLIENT__ ) {
194- dispatch ( search ( location . query ) ) ;
192+ dispatch ( search ( location . query || location . q ) ) ;
195193 return false ;
196194 }
197195
198- return dispatch ( search ( location . query ) ) ;
196+ return dispatch ( search ( location . query || location . q ) ) ;
199197 }
200198} ] ) ( Search ) ;
201199
202200function mapStateToProps ( state ) {
203201 return {
204202 isErrored : state . searchResults . errored ,
205203 isLoading : state . searchResults . loading ,
206- total : state . searchResults . total ,
207- page : state . searchResults . page ,
208- size : state . searchResults . size ,
209- from : state . searchResults . from ,
204+ totalCount : state . searchResults . totalCount ,
205+ currentPage : state . searchResults . currentPage ,
206+ totalPages : state . searchResults . totalPages ,
207+ perPage : state . searchResults . perPage ,
210208 took : state . searchResults . took ,
211209 query : state . searchResults . query ,
212210 results : state . searchResults . results ,
213- verses : state . searchResults . entities ,
214211 options : state . options
215212 } ;
216213}
0 commit comments