Merge pull request #1152 from FrenchBen/1151-pagination

Added reset of pagination for new search. Fixes #1151
This commit is contained in:
French Ben 2015-10-28 15:47:56 -07:00
Родитель c1b9dc5fce 9f05ce192e
Коммит f15c523080
2 изменённых файлов: 11 добавлений и 7 удалений

Просмотреть файл

@ -66,16 +66,21 @@ module.exports = React.createClass({
_searchPromise.cancel();
_searchPromise = null;
}
let previousPage = (page - 1 < 1) ? 1 : page - 1;
let nextPage = (page + 1 > this.state.totalPage) ? this.state.totalPage : page + 1;
let previousPage, nextPage, totalPage = null;
// If query remains, retain pagination
if (this.state.query === query) {
previousPage = (page - 1 < 1) ? 1 : page - 1;
nextPage = (page + 1 > this.state.totalPage) ? this.state.totalPage : page + 1;
totalPage = this.state.totalPage;
}
this.setState({
query: query,
loading: true,
currentPage: page,
previousPage: previousPage,
nextPage: nextPage
nextPage: nextPage,
totalPage: totalPage
});
_searchPromise = Promise.delay(200).cancellable().then(() => {
@ -174,8 +179,7 @@ module.exports = React.createClass({
<span>{this.state.currentPage} <span className="sr-only">(current)</span></span>
</li>
);
paginateResults = next.length || previous.length ? (
paginateResults = (next.length || previous.length) && (this.state.query !== '') ? (
<nav>
<ul className="pagination">
{previous}

Просмотреть файл

@ -52,7 +52,7 @@ class RepositoryStore {
let nextPage = (page + 1 > this.totalPage) ? this.totalPage : page + 1;
this.setState({query: query, error: null, resultsLoading: true, currentPage: page, nextPage: nextPage, previousPage: previousPage});
} else {
this.setState({query: query, error: null, resultsLoading: true, nextPage: null, previousPage: null, currentPage: 1});
this.setState({query: query, error: null, resultsLoading: true, nextPage: null, previousPage: null, currentPage: 1, totalPage: null});
}
}