From 48b1f1507078116989926fe2e887581592a32b33 Mon Sep 17 00:00:00 2001 From: Niels Simenon Date: Mon, 10 Feb 2020 01:27:13 +0100 Subject: [PATCH] Restoring scroll position when going from home to scene to home. --- assets/components/home/home.vue | 13 +++++++++++++ assets/components/releases/releases.vue | 9 ++++++++- assets/components/tile/release.vue | 23 ++++++++++++----------- assets/js/fragments.js | 1 + assets/js/router.js | 9 ++++++++- migrations/20190325001339_releases.js | 3 ++- 6 files changed, 44 insertions(+), 14 deletions(-) diff --git a/assets/components/home/home.vue b/assets/components/home/home.vue index 8bb14d48..2b69461a 100644 --- a/assets/components/home/home.vue +++ b/assets/components/home/home.vue @@ -5,6 +5,7 @@
@@ -24,6 +25,13 @@ async function mounted() { await this.fetchReleases(); } +function updated() { + if (this.from.name === 'scene' && this.from.hash === '#home') { + const releaseTile = document.querySelector(`#scene-${this.from.params.releaseId}`); + if (releaseTile) releaseTile.scrollIntoView(); + } +} + export default { components: { FilterBar, @@ -34,8 +42,13 @@ export default { releases: [], networks: [], pageTitle: null, + from: null, }; }, + beforeRouteEnter(to, from, next) { + next(vm => vm.$set(vm, 'from', from)); + }, + updated, mounted, methods: { fetchReleases, diff --git a/assets/components/releases/releases.vue b/assets/components/releases/releases.vue index e4aed20e..ceb1746c 100644 --- a/assets/components/releases/releases.vue +++ b/assets/components/releases/releases.vue @@ -10,7 +10,10 @@ v-for="release in releases" :key="`release-${release.id}`" > - + @@ -46,6 +49,10 @@ export default { type: String, default: null, }, + referer: { + type: String, + default: null, + }, }, computed: { range, diff --git a/assets/components/tile/release.vue b/assets/components/tile/release.vue index 97390899..205d8849 100644 --- a/assets/components/tile/release.vue +++ b/assets/components/tile/release.vue @@ -1,7 +1,8 @@