diff --git a/components/bookshelf/LazyBookshelf.vue b/components/bookshelf/LazyBookshelf.vue index e865d09f..63f4fa6a 100644 --- a/components/bookshelf/LazyBookshelf.vue +++ b/components/bookshelf/LazyBookshelf.vue @@ -25,6 +25,7 @@ export default { mixins: [bookshelfCardsHelpers], data() { return { + routeFullPath: null, entitiesPerShelf: 2, bookshelfHeight: 0, bookshelfWidth: 0, @@ -72,6 +73,7 @@ export default { return this.page }, hasFilter() { + if (this.page === 'series' || this.page === 'collections') return false return this.filterBy !== 'all' }, orderBy() { @@ -316,6 +318,15 @@ export default { await this.loadPage(0) var lastBookIndex = Math.min(this.totalEntities, this.shelvesPerPage * this.entitiesPerShelf) this.mountEntites(0, lastBookIndex) + + // Set last scroll position for this bookshelf page + if (this.$store.state.lastBookshelfScrollData[this.page] && window['bookshelf-wrapper']) { + const { path, scrollTop } = this.$store.state.lastBookshelfScrollData[this.page] + if (path === this.routeFullPath) { + // Exact path match with query so use scroll position + window['bookshelf-wrapper'].scrollTop = scrollTop + } + } }, scroll(e) { if (!e || !e.target) return @@ -358,6 +369,8 @@ export default { if (newSearchParams !== this.currentSFQueryString || newSearchParams !== currentQueryString) { let newurl = window.location.protocol + '//' + window.location.host + window.location.pathname + '?' + newSearchParams window.history.replaceState({ path: newurl }, '', newurl) + + this.routeFullPath = window.location.pathname + (window.location.search || '') // Update for saving scroll position return true } @@ -452,12 +465,22 @@ export default { this.$socket.$off('items_added', this.libraryItemsAdded) } }, + updated() { + this.routeFullPath = window.location.pathname + (window.location.search || '') + }, mounted() { + this.routeFullPath = window.location.pathname + (window.location.search || '') + this.init() this.initListeners() }, beforeDestroy() { this.removeListeners() + + // Set bookshelf scroll position for specific bookshelf page and query + if (window['bookshelf-wrapper']) { + this.$store.commit('setLastBookshelfScrollData', { scrollTop: window['bookshelf-wrapper'].scrollTop || 0, path: this.routeFullPath, name: this.page }) + } } } diff --git a/store/index.js b/store/index.js index d9a685dd..d2c8aa3a 100644 --- a/store/index.js +++ b/store/index.js @@ -16,7 +16,8 @@ export const state = () => ({ showReader: false, showSideDrawer: false, isNetworkListenerInit: false, - serverSettings: null + serverSettings: null, + lastBookshelfScrollData: {} }) export const getters = { @@ -54,6 +55,9 @@ export const actions = { } export const mutations = { + setLastBookshelfScrollData(state, { scrollTop, path, name }) { + state.lastBookshelfScrollData[name] = { scrollTop, path } + }, setPlayerItem(state, playbackSession) { state.playerIsLocal = playbackSession ? playbackSession.playMethod == this.$constants.PlayMethod.LOCAL : false