From 5d8dd9cb05f084177a102b1197d8b6f4a247ad58 Mon Sep 17 00:00:00 2001 From: rr- Date: Fri, 8 Jul 2016 00:46:48 +0200 Subject: [PATCH] client/paging: fix endless scroll return path Since some refactors it has always been returning to page 1. --- client/js/main.js | 2 +- client/js/router.js | 12 +++++++++--- client/js/views/endless_page_view.js | 2 +- client/js/views/posts_header_view.js | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/client/js/main.js b/client/js/main.js index 1cca87d6..d90add72 100644 --- a/client/js/main.js +++ b/client/js/main.js @@ -12,7 +12,7 @@ router.exit( (ctx, next) => { ctx.state.scrollX = window.scrollX; ctx.state.scrollY = window.scrollY; - ctx.save(); + router.replace(router.url, ctx.state); if (misc.confirmPageExit()) { next(); } diff --git a/client/js/router.js b/client/js/router.js index cfe405f1..22260590 100644 --- a/client/js/router.js +++ b/client/js/router.js @@ -6,6 +6,8 @@ // - simplified method chains // - added ability to call .save() in .exit() without side effects // - page refresh recovers state from history +// - rename .save() to .replaceState() +// - offer .url const pathToRegexp = require('path-to-regexp'); const clickEvent = document.ontouchstart ? 'touchstart' : 'click'; @@ -47,7 +49,7 @@ class Context { history.pushState(this.state, this.title, this.canonicalPath); } - save() { + replaceState() { history.replaceState(this.state, this.title, this.canonicalPath); } }; @@ -149,10 +151,10 @@ class Router { var ctx = new Context(path, state); if (dispatch) { this.dispatch(ctx, () => { - ctx.save(); + ctx.replaceState(); }); } else { - ctx.save(); + ctx.replaceState(); } return ctx; } @@ -184,6 +186,10 @@ class Router { router.stop(); location.href = ctx.canonicalPath; } + + get url() { + return location.pathname + location.search + location.hash; + } }; const _onPopState = router => { diff --git a/client/js/views/endless_page_view.js b/client/js/views/endless_page_view.js index 142a6dc3..8bf6a0d6 100644 --- a/client/js/views/endless_page_view.js +++ b/client/js/views/endless_page_view.js @@ -65,7 +65,7 @@ class EndlessPageView { if (topPageNumber !== this.currentPage) { router.replace( ctx.getClientUrlForPage(topPageNumber), - {}, + ctx.state, false); this.currentPage = topPageNumber; } diff --git a/client/js/views/posts_header_view.js b/client/js/views/posts_header_view.js index 6824b87f..da95a308 100644 --- a/client/js/views/posts_header_view.js +++ b/client/js/views/posts_header_view.js @@ -110,7 +110,7 @@ class PostsHeaderView { browsingSettings.listPosts[safety] = !browsingSettings.listPosts[safety]; settings.save(browsingSettings, true); - router.show(location.pathname + location.search + location.hash); + router.show(router.url); } _evtSearchFormSubmit(e) {