client/paging: remember results in history

This commit is contained in:
rr- 2016-06-12 22:02:15 +02:00
parent 95b3b09cbc
commit 0547ec5aa2
5 changed files with 48 additions and 24 deletions

View file

@ -23,12 +23,14 @@ class CommentsController {
pageController.run({ pageController.run({
searchQuery: ctx.searchQuery, searchQuery: ctx.searchQuery,
clientUrl: '/comments/' + misc.formatSearchQuery({page: '{page}'}), clientUrl: '/comments/' + misc.formatSearchQuery({page: '{page}'}),
requestPage: page => { requestPage: pageController.createHistoryCacheProxy(
ctx,
page => {
return api.get( return api.get(
'/posts/?query=sort:comment-date+comment-count-min:1' + '/posts/?query=sort:comment-date+comment-count-min:1' +
`&page=${page}&pageSize=10&fields=` + `&page=${page}&pageSize=10&fields=` +
'id,comments,commentCount,thumbnailUrl'); 'id,comments,commentCount,thumbnailUrl');
}, }),
pageRenderer: this._commentsPageView, pageRenderer: this._commentsPageView,
pageContext: { pageContext: {
canViewPosts: api.hasPrivilege('posts:view'), canViewPosts: api.hasPrivilege('posts:view'),

View file

@ -37,6 +37,22 @@ class PageController {
this._pageView.render(ctx); 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() { stop() {
this._pageView.unrender(); this._pageView.unrender();
} }

View file

@ -48,13 +48,15 @@ class PostsController {
searchQuery: ctx.searchQuery, searchQuery: ctx.searchQuery,
clientUrl: '/posts/' + misc.formatSearchQuery({ clientUrl: '/posts/' + misc.formatSearchQuery({
text: ctx.searchQuery.text, page: '{page}'}), text: ctx.searchQuery.text, page: '{page}'}),
requestPage: page => { requestPage: pageController.createHistoryCacheProxy(
ctx,
page => {
const text = this._decorateSearchQuery(ctx.searchQuery.text); const text = this._decorateSearchQuery(ctx.searchQuery.text);
return api.get( return api.get(
`/posts/?query=${text}&page=${page}&pageSize=40&fields=` + `/posts/?query=${text}&page=${page}&pageSize=40` +
`id,type,tags,score,favoriteCount,` + '&fields=id,type,tags,score,favoriteCount,' +
`commentCount,thumbnailUrl`); 'commentCount,thumbnailUrl');
}, }),
headerRenderer: this._postsHeaderView, headerRenderer: this._postsHeaderView,
pageRenderer: this._postsPageView, pageRenderer: this._postsPageView,
pageContext: { pageContext: {

View file

@ -207,12 +207,14 @@ class TagsController {
searchQuery: ctx.searchQuery, searchQuery: ctx.searchQuery,
clientUrl: '/tags/' + misc.formatSearchQuery({ clientUrl: '/tags/' + misc.formatSearchQuery({
text: ctx.searchQuery.text, page: '{page}'}), text: ctx.searchQuery.text, page: '{page}'}),
requestPage: page => { requestPage: pageController.createHistoryCacheProxy(
ctx,
page => {
const text = ctx.searchQuery.text; const text = ctx.searchQuery.text;
return api.get( return api.get(
`/tags/?query=${text}&page=${page}&pageSize=50&fields=` + `/tags/?query=${text}&page=${page}&pageSize=50&fields=` +
`names,suggestions,implications,lastEditTime,usages`); `names,suggestions,implications,lastEditTime,usages`);
}, }),
headerRenderer: this._tagsHeaderView, headerRenderer: this._tagsHeaderView,
pageRenderer: this._tagsPageView, pageRenderer: this._tagsPageView,
headerContext: { headerContext: {

View file

@ -71,11 +71,13 @@ class UsersController {
searchQuery: ctx.searchQuery, searchQuery: ctx.searchQuery,
clientUrl: '/users/' + misc.formatSearchQuery({ clientUrl: '/users/' + misc.formatSearchQuery({
text: ctx.searchQuery.text, page: '{page}'}), text: ctx.searchQuery.text, page: '{page}'}),
requestPage: page => { requestPage: pageController.createHistoryCacheProxy(
ctx,
page => {
const text = ctx.searchQuery.text; const text = ctx.searchQuery.text;
return api.get( return api.get(
`/users/?query=${text}&page=${page}&pageSize=30`); `/users/?query=${text}&page=${page}&pageSize=30`);
}, }),
headerRenderer: this._usersHeaderView, headerRenderer: this._usersHeaderView,
pageRenderer: this._usersPageView, pageRenderer: this._usersPageView,
pageContext: { pageContext: {