Add:Persist scroll position for bookshelves #196, Fix:Hide clear filter button for series and collections

This commit is contained in:
advplyr 2022-05-22 14:19:13 -05:00
parent 5d2da97dc5
commit 61b8ca1510
2 changed files with 28 additions and 1 deletions

View file

@ -25,6 +25,7 @@ export default {
mixins: [bookshelfCardsHelpers], mixins: [bookshelfCardsHelpers],
data() { data() {
return { return {
routeFullPath: null,
entitiesPerShelf: 2, entitiesPerShelf: 2,
bookshelfHeight: 0, bookshelfHeight: 0,
bookshelfWidth: 0, bookshelfWidth: 0,
@ -72,6 +73,7 @@ export default {
return this.page return this.page
}, },
hasFilter() { hasFilter() {
if (this.page === 'series' || this.page === 'collections') return false
return this.filterBy !== 'all' return this.filterBy !== 'all'
}, },
orderBy() { orderBy() {
@ -316,6 +318,15 @@ export default {
await this.loadPage(0) await this.loadPage(0)
var lastBookIndex = Math.min(this.totalEntities, this.shelvesPerPage * this.entitiesPerShelf) var lastBookIndex = Math.min(this.totalEntities, this.shelvesPerPage * this.entitiesPerShelf)
this.mountEntites(0, lastBookIndex) 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) { scroll(e) {
if (!e || !e.target) return if (!e || !e.target) return
@ -358,6 +369,8 @@ export default {
if (newSearchParams !== this.currentSFQueryString || newSearchParams !== currentQueryString) { if (newSearchParams !== this.currentSFQueryString || newSearchParams !== currentQueryString) {
let newurl = window.location.protocol + '//' + window.location.host + window.location.pathname + '?' + newSearchParams let newurl = window.location.protocol + '//' + window.location.host + window.location.pathname + '?' + newSearchParams
window.history.replaceState({ path: newurl }, '', newurl) window.history.replaceState({ path: newurl }, '', newurl)
this.routeFullPath = window.location.pathname + (window.location.search || '') // Update for saving scroll position
return true return true
} }
@ -452,12 +465,22 @@ export default {
this.$socket.$off('items_added', this.libraryItemsAdded) this.$socket.$off('items_added', this.libraryItemsAdded)
} }
}, },
updated() {
this.routeFullPath = window.location.pathname + (window.location.search || '')
},
mounted() { mounted() {
this.routeFullPath = window.location.pathname + (window.location.search || '')
this.init() this.init()
this.initListeners() this.initListeners()
}, },
beforeDestroy() { beforeDestroy() {
this.removeListeners() 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 })
}
} }
} }
</script> </script>

View file

@ -16,7 +16,8 @@ export const state = () => ({
showReader: false, showReader: false,
showSideDrawer: false, showSideDrawer: false,
isNetworkListenerInit: false, isNetworkListenerInit: false,
serverSettings: null serverSettings: null,
lastBookshelfScrollData: {}
}) })
export const getters = { export const getters = {
@ -54,6 +55,9 @@ export const actions = {
} }
export const mutations = { export const mutations = {
setLastBookshelfScrollData(state, { scrollTop, path, name }) {
state.lastBookshelfScrollData[name] = { scrollTop, path }
},
setPlayerItem(state, playbackSession) { setPlayerItem(state, playbackSession) {
state.playerIsLocal = playbackSession ? playbackSession.playMethod == this.$constants.PlayMethod.LOCAL : false state.playerIsLocal = playbackSession ? playbackSession.playMethod == this.$constants.PlayMethod.LOCAL : false