client/paging: fix endless scroll return path

Since some refactors it has always been returning to page 1.
This commit is contained in:
rr- 2016-07-08 00:46:48 +02:00
parent 8901658c17
commit 5d8dd9cb05
4 changed files with 12 additions and 6 deletions

View File

@ -12,7 +12,7 @@ router.exit(
(ctx, next) => { (ctx, next) => {
ctx.state.scrollX = window.scrollX; ctx.state.scrollX = window.scrollX;
ctx.state.scrollY = window.scrollY; ctx.state.scrollY = window.scrollY;
ctx.save(); router.replace(router.url, ctx.state);
if (misc.confirmPageExit()) { if (misc.confirmPageExit()) {
next(); next();
} }

View File

@ -6,6 +6,8 @@
// - simplified method chains // - simplified method chains
// - added ability to call .save() in .exit() without side effects // - added ability to call .save() in .exit() without side effects
// - page refresh recovers state from history // - page refresh recovers state from history
// - rename .save() to .replaceState()
// - offer .url
const pathToRegexp = require('path-to-regexp'); const pathToRegexp = require('path-to-regexp');
const clickEvent = document.ontouchstart ? 'touchstart' : 'click'; const clickEvent = document.ontouchstart ? 'touchstart' : 'click';
@ -47,7 +49,7 @@ class Context {
history.pushState(this.state, this.title, this.canonicalPath); history.pushState(this.state, this.title, this.canonicalPath);
} }
save() { replaceState() {
history.replaceState(this.state, this.title, this.canonicalPath); history.replaceState(this.state, this.title, this.canonicalPath);
} }
}; };
@ -149,10 +151,10 @@ class Router {
var ctx = new Context(path, state); var ctx = new Context(path, state);
if (dispatch) { if (dispatch) {
this.dispatch(ctx, () => { this.dispatch(ctx, () => {
ctx.save(); ctx.replaceState();
}); });
} else { } else {
ctx.save(); ctx.replaceState();
} }
return ctx; return ctx;
} }
@ -184,6 +186,10 @@ class Router {
router.stop(); router.stop();
location.href = ctx.canonicalPath; location.href = ctx.canonicalPath;
} }
get url() {
return location.pathname + location.search + location.hash;
}
}; };
const _onPopState = router => { const _onPopState = router => {

View File

@ -65,7 +65,7 @@ class EndlessPageView {
if (topPageNumber !== this.currentPage) { if (topPageNumber !== this.currentPage) {
router.replace( router.replace(
ctx.getClientUrlForPage(topPageNumber), ctx.getClientUrlForPage(topPageNumber),
{}, ctx.state,
false); false);
this.currentPage = topPageNumber; this.currentPage = topPageNumber;
} }

View File

@ -110,7 +110,7 @@ class PostsHeaderView {
browsingSettings.listPosts[safety] = browsingSettings.listPosts[safety] =
!browsingSettings.listPosts[safety]; !browsingSettings.listPosts[safety];
settings.save(browsingSettings, true); settings.save(browsingSettings, true);
router.show(location.pathname + location.search + location.hash); router.show(router.url);
} }
_evtSearchFormSubmit(e) { _evtSearchFormSubmit(e) {