client/paging: remember results in history
This commit is contained in:
parent
95b3b09cbc
commit
0547ec5aa2
5 changed files with 48 additions and 24 deletions
|
@ -23,12 +23,14 @@ class CommentsController {
|
|||
pageController.run({
|
||||
searchQuery: ctx.searchQuery,
|
||||
clientUrl: '/comments/' + misc.formatSearchQuery({page: '{page}'}),
|
||||
requestPage: page => {
|
||||
requestPage: pageController.createHistoryCacheProxy(
|
||||
ctx,
|
||||
page => {
|
||||
return api.get(
|
||||
'/posts/?query=sort:comment-date+comment-count-min:1' +
|
||||
`&page=${page}&pageSize=10&fields=` +
|
||||
'id,comments,commentCount,thumbnailUrl');
|
||||
},
|
||||
}),
|
||||
pageRenderer: this._commentsPageView,
|
||||
pageContext: {
|
||||
canViewPosts: api.hasPrivilege('posts:view'),
|
||||
|
|
|
@ -37,6 +37,22 @@ class PageController {
|
|||
this._pageView.render(ctx);
|
||||
}
|
||||
|
||||
createHistoryCacheProxy(routerCtx, requestPage) {
|
||||
return page => {
|
||||
if (routerCtx.state.response) {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(routerCtx.state.response);
|
||||
});
|
||||
}
|
||||
const promise = requestPage(page);
|
||||
promise.then(response => {
|
||||
routerCtx.state.response = response;
|
||||
routerCtx.save();
|
||||
});
|
||||
return promise;
|
||||
};
|
||||
}
|
||||
|
||||
stop() {
|
||||
this._pageView.unrender();
|
||||
}
|
||||
|
|
|
@ -48,13 +48,15 @@ class PostsController {
|
|||
searchQuery: ctx.searchQuery,
|
||||
clientUrl: '/posts/' + misc.formatSearchQuery({
|
||||
text: ctx.searchQuery.text, page: '{page}'}),
|
||||
requestPage: page => {
|
||||
requestPage: pageController.createHistoryCacheProxy(
|
||||
ctx,
|
||||
page => {
|
||||
const text = this._decorateSearchQuery(ctx.searchQuery.text);
|
||||
return api.get(
|
||||
`/posts/?query=${text}&page=${page}&pageSize=40&fields=` +
|
||||
`id,type,tags,score,favoriteCount,` +
|
||||
`commentCount,thumbnailUrl`);
|
||||
},
|
||||
`/posts/?query=${text}&page=${page}&pageSize=40` +
|
||||
'&fields=id,type,tags,score,favoriteCount,' +
|
||||
'commentCount,thumbnailUrl');
|
||||
}),
|
||||
headerRenderer: this._postsHeaderView,
|
||||
pageRenderer: this._postsPageView,
|
||||
pageContext: {
|
||||
|
|
|
@ -207,12 +207,14 @@ class TagsController {
|
|||
searchQuery: ctx.searchQuery,
|
||||
clientUrl: '/tags/' + misc.formatSearchQuery({
|
||||
text: ctx.searchQuery.text, page: '{page}'}),
|
||||
requestPage: page => {
|
||||
requestPage: pageController.createHistoryCacheProxy(
|
||||
ctx,
|
||||
page => {
|
||||
const text = ctx.searchQuery.text;
|
||||
return api.get(
|
||||
`/tags/?query=${text}&page=${page}&pageSize=50&fields=` +
|
||||
`names,suggestions,implications,lastEditTime,usages`);
|
||||
},
|
||||
}),
|
||||
headerRenderer: this._tagsHeaderView,
|
||||
pageRenderer: this._tagsPageView,
|
||||
headerContext: {
|
||||
|
|
|
@ -71,11 +71,13 @@ class UsersController {
|
|||
searchQuery: ctx.searchQuery,
|
||||
clientUrl: '/users/' + misc.formatSearchQuery({
|
||||
text: ctx.searchQuery.text, page: '{page}'}),
|
||||
requestPage: page => {
|
||||
requestPage: pageController.createHistoryCacheProxy(
|
||||
ctx,
|
||||
page => {
|
||||
const text = ctx.searchQuery.text;
|
||||
return api.get(
|
||||
`/users/?query=${text}&page=${page}&pageSize=30`);
|
||||
},
|
||||
}),
|
||||
headerRenderer: this._usersHeaderView,
|
||||
pageRenderer: this._usersPageView,
|
||||
pageContext: {
|
||||
|
|
Loading…
Reference in a new issue