diff --git a/frontend/src/pages/search/main-panel.js b/frontend/src/pages/search/main-panel.js index 85d2d655ff..4d275a0731 100644 --- a/frontend/src/pages/search/main-panel.js +++ b/frontend/src/pages/search/main-panel.js @@ -1,5 +1,4 @@ import React from 'react'; -import moment from 'moment'; import { gettext } from '../../utils/constants'; import { seafileAPI } from '../../utils/seafile-api'; import SearchResults from './search-results'; @@ -52,17 +51,19 @@ class SearchViewPanel extends React.Component { }); const stateHistory = _.cloneDeep(this.state); seafileAPI.searchFiles(params, null).then(res => { + const { results, has_more, total } = res.data; this.setState({ isLoading: false, isResultGot: true, - resultItems: res.data.results, - hasMore: res.data.has_more, + resultItems: results, + hasMore: has_more, + total: total, page: params.page, isShowSearchFilter: true, }); this.stateHistory = stateHistory; - this.stateHistory.resultItems = res.data.results; - this.stateHistory.hasMore = res.data.has_more; + this.stateHistory.resultItems = results; + this.stateHistory.hasMore = has_more; this.stateHistory.page = params.page; }).catch((error) => { this.setState({ isLoading: false }); @@ -145,7 +146,8 @@ class SearchViewPanel extends React.Component { }); } - handlePrevious = () => { + handlePrevious = (e) => { + e.preventDefault(); if (this.stateHistory && this.state.page > 1) { this.setState(this.stateHistory,() => { const params = this.handleSearchParams(this.state.page - 1); @@ -156,7 +158,8 @@ class SearchViewPanel extends React.Component { } }; - handleNext = () => { + handleNext = (e) => { + e.preventDefault(); if (this.stateHistory && this.state.hasMore) { this.setState(this.stateHistory,() => { const params = this.handleSearchParams(this.state.page + 1); @@ -321,12 +324,17 @@ class SearchViewPanel extends React.Component { /> {this.state.isLoading && } - {(!this.state.isLoading && this.state.isResultGot) && } + {(!this.state.isLoading && this.state.isResultGot) && + + } {(!this.state.isLoading && this.state.isResultGot) &&
- {this.state.page !== 1 && this.handlePrevious()}>{gettext('Previous')}} + {this.state.page !== 1 && {gettext('Previous')}} {(this.state.page !== 1 && this.state.hasMore) && | } - {this.state.hasMore && this.handleNext()}>{gettext('Next')}} + {this.state.hasMore && {gettext('Next')}}
} diff --git a/frontend/src/pages/search/search-results.js b/frontend/src/pages/search/search-results.js index f84d996f0d..43ffcaf969 100644 --- a/frontend/src/pages/search/search-results.js +++ b/frontend/src/pages/search/search-results.js @@ -39,10 +39,10 @@ class ResultsItem extends React.Component {
- {item.name} + {item.name}
- {item.repo_name}{this.handlerParentDirPath(item)} + {item.repo_name}{this.handlerParentDirPath(item)}
{Utils.bytesToSize(item.size) + ' ' + moment(item.last_modified * 1000).format('YYYY-MM-DD')} @@ -67,12 +67,11 @@ class SearchResults extends React.Component { } render() { - const { resultItems } = this.props; - const total = resultItems.length; + const { resultItems, total } = this.props; return (
+

{total > 0 ? (total + ' ' + (total === 1 ? gettext('result') : gettext('results'))) : gettext('No result')}

    -

    {total > 0 ? (total + ' ' + (total === 1 ? gettext('result') : gettext('results'))) : gettext('No result')}

    {resultItems.map((item, index) => { return ; })} @@ -84,6 +83,7 @@ class SearchResults extends React.Component { const searchResultsPropTypes = { resultItems: PropTypes.array.isRequired, + total: PropTypes.number.isRequired }; SearchResults.propTypes = searchResultsPropTypes;