2021-12-04 19:56:29 -06:00
|
|
|
<template>
|
2021-12-05 18:31:47 -06:00
|
|
|
<div id="bookshelf" class="w-full max-w-full h-full">
|
2021-12-04 19:56:29 -06:00
|
|
|
<template v-for="shelf in totalShelves">
|
2022-07-27 18:21:10 -05:00
|
|
|
<div :key="shelf" class="w-full px-2 relative" :class="showBookshelfListView || altViewEnabled ? '' : 'bookshelfRow'" :id="`shelf-${shelf - 1}`" :style="{ height: shelfHeight + 'px' }">
|
|
|
|
<div v-if="!showBookshelfListView && !altViewEnabled" class="w-full absolute bottom-0 left-0 z-30 bookshelfDivider" style="min-height: 16px" :class="`h-${shelfDividerHeightIndex}`" />
|
|
|
|
<div v-else-if="showBookshelfListView" class="flex border-t border-white border-opacity-10" />
|
2021-12-04 19:56:29 -06:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<div v-show="!entities.length && initialized" class="w-full py-16 text-center text-xl">
|
|
|
|
<div class="py-4 capitalize">No {{ entityName }}</div>
|
|
|
|
<ui-btn v-if="hasFilter" @click="clearFilter">Clear Filter</ui-btn>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import bookshelfCardsHelpers from '@/mixins/bookshelfCardsHelpers'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
page: String,
|
|
|
|
seriesId: String
|
|
|
|
},
|
|
|
|
mixins: [bookshelfCardsHelpers],
|
|
|
|
data() {
|
|
|
|
return {
|
2022-05-22 14:19:13 -05:00
|
|
|
routeFullPath: null,
|
2022-05-12 18:24:36 -05:00
|
|
|
entitiesPerShelf: 2,
|
2021-12-04 19:56:29 -06:00
|
|
|
bookshelfHeight: 0,
|
|
|
|
bookshelfWidth: 0,
|
|
|
|
bookshelfMarginLeft: 0,
|
|
|
|
shelvesPerPage: 0,
|
|
|
|
currentPage: 0,
|
|
|
|
booksPerFetch: 20,
|
|
|
|
initialized: false,
|
|
|
|
currentSFQueryString: null,
|
|
|
|
isFetchingEntities: false,
|
|
|
|
entities: [],
|
|
|
|
totalEntities: 0,
|
|
|
|
totalShelves: 0,
|
|
|
|
entityComponentRefs: {},
|
|
|
|
entityIndexesMounted: [],
|
|
|
|
pagesLoaded: {},
|
|
|
|
isFirstInit: false,
|
2022-04-07 18:46:58 -05:00
|
|
|
pendingReset: false,
|
|
|
|
localLibraryItems: []
|
2021-12-04 19:56:29 -06:00
|
|
|
}
|
|
|
|
},
|
2022-04-07 19:59:23 -05:00
|
|
|
watch: {
|
|
|
|
showBookshelfListView(newVal) {
|
|
|
|
this.resetEntities()
|
2023-03-04 14:12:16 -06:00
|
|
|
},
|
|
|
|
seriesId() {
|
|
|
|
this.resetEntities()
|
2022-04-07 19:59:23 -05:00
|
|
|
}
|
|
|
|
},
|
2021-12-04 19:56:29 -06:00
|
|
|
computed: {
|
2022-04-04 19:08:27 -05:00
|
|
|
user() {
|
|
|
|
return this.$store.state.user.user
|
2021-12-04 19:56:29 -06:00
|
|
|
},
|
|
|
|
isBookEntity() {
|
|
|
|
return this.entityName === 'books' || this.entityName === 'series-books'
|
|
|
|
},
|
|
|
|
shelfDividerHeightIndex() {
|
|
|
|
if (this.isBookEntity) return 4
|
|
|
|
return 6
|
|
|
|
},
|
2022-04-07 19:59:23 -05:00
|
|
|
bookshelfListView() {
|
|
|
|
return this.$store.state.globals.bookshelfListView
|
|
|
|
},
|
|
|
|
showBookshelfListView() {
|
|
|
|
return this.isBookEntity && this.bookshelfListView
|
|
|
|
},
|
2021-12-04 19:56:29 -06:00
|
|
|
entityName() {
|
|
|
|
return this.page
|
|
|
|
},
|
|
|
|
hasFilter() {
|
2022-05-22 14:19:13 -05:00
|
|
|
if (this.page === 'series' || this.page === 'collections') return false
|
2021-12-04 19:56:29 -06:00
|
|
|
return this.filterBy !== 'all'
|
|
|
|
},
|
|
|
|
orderBy() {
|
|
|
|
return this.$store.getters['user/getUserSetting']('mobileOrderBy')
|
|
|
|
},
|
|
|
|
orderDesc() {
|
|
|
|
return this.$store.getters['user/getUserSetting']('mobileOrderDesc')
|
|
|
|
},
|
|
|
|
filterBy() {
|
|
|
|
return this.$store.getters['user/getUserSetting']('mobileFilterBy')
|
|
|
|
},
|
2023-03-03 17:05:23 -06:00
|
|
|
collapseSeries() {
|
|
|
|
return this.$store.getters['user/getUserSetting']('collapseSeries')
|
|
|
|
},
|
|
|
|
collapseBookSeries() {
|
|
|
|
return this.$store.getters['user/getUserSetting']('collapseBookSeries')
|
|
|
|
},
|
2021-12-04 19:56:29 -06:00
|
|
|
isCoverSquareAspectRatio() {
|
2022-05-13 13:42:38 -05:00
|
|
|
return this.bookCoverAspectRatio === 1
|
2021-12-04 19:56:29 -06:00
|
|
|
},
|
|
|
|
bookCoverAspectRatio() {
|
2022-10-22 08:59:10 -05:00
|
|
|
return this.$store.getters['libraries/getBookCoverAspectRatio']
|
2021-12-04 19:56:29 -06:00
|
|
|
},
|
|
|
|
bookWidth() {
|
|
|
|
var coverSize = 100
|
2021-12-31 16:57:53 -06:00
|
|
|
if (window.innerWidth <= 375) coverSize = 90
|
|
|
|
|
2022-12-03 15:20:27 -06:00
|
|
|
if (this.isCoverSquareAspectRatio || this.entityName === 'playlists') return coverSize * 1.6
|
2021-12-04 19:56:29 -06:00
|
|
|
return coverSize
|
|
|
|
},
|
|
|
|
bookHeight() {
|
2022-12-03 15:20:27 -06:00
|
|
|
if (this.isCoverSquareAspectRatio || this.entityName === 'playlists') return this.bookWidth
|
2021-12-04 19:56:29 -06:00
|
|
|
return this.bookWidth * 1.6
|
|
|
|
},
|
|
|
|
entityWidth() {
|
2022-04-07 19:59:23 -05:00
|
|
|
if (this.showBookshelfListView) return this.bookshelfWidth - 16
|
2022-12-03 15:20:27 -06:00
|
|
|
if (this.isBookEntity || this.entityName === 'playlists') return this.bookWidth
|
2021-12-04 19:56:29 -06:00
|
|
|
return this.bookWidth * 2
|
|
|
|
},
|
|
|
|
entityHeight() {
|
2022-04-07 19:59:23 -05:00
|
|
|
if (this.showBookshelfListView) return 88
|
2021-12-04 19:56:29 -06:00
|
|
|
return this.bookHeight
|
|
|
|
},
|
|
|
|
currentLibraryId() {
|
|
|
|
return this.$store.state.libraries.currentLibraryId
|
|
|
|
},
|
2022-04-07 18:46:58 -05:00
|
|
|
currentLibraryMediaType() {
|
|
|
|
return this.$store.getters['libraries/getCurrentLibraryMediaType']
|
|
|
|
},
|
2021-12-04 19:56:29 -06:00
|
|
|
shelfHeight() {
|
2022-05-12 18:24:36 -05:00
|
|
|
if (this.showBookshelfListView) return this.entityHeight + 16
|
2022-07-27 18:21:10 -05:00
|
|
|
if (this.altViewEnabled) {
|
|
|
|
var extraTitleSpace = this.isBookEntity ? 80 : 40
|
|
|
|
return this.entityHeight + extraTitleSpace * this.sizeMultiplier
|
|
|
|
}
|
2021-12-04 19:56:29 -06:00
|
|
|
return this.entityHeight + 40
|
|
|
|
},
|
|
|
|
totalEntityCardWidth() {
|
2022-04-07 19:59:23 -05:00
|
|
|
if (this.showBookshelfListView) return this.entityWidth
|
2021-12-04 19:56:29 -06:00
|
|
|
// Includes margin
|
|
|
|
return this.entityWidth + 24
|
2022-07-27 13:29:07 -05:00
|
|
|
},
|
|
|
|
altViewEnabled() {
|
2022-07-27 18:21:10 -05:00
|
|
|
return this.$store.getters['getAltViewEnabled']
|
|
|
|
},
|
|
|
|
sizeMultiplier() {
|
2022-12-10 14:17:18 -06:00
|
|
|
const baseSize = this.isCoverSquareAspectRatio ? 192 : 120
|
2022-07-27 18:21:10 -05:00
|
|
|
return this.entityWidth / baseSize
|
2021-12-04 19:56:29 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
clearFilter() {
|
|
|
|
this.$store.dispatch('user/updateUserSettings', {
|
|
|
|
mobileFilterBy: 'all'
|
|
|
|
})
|
|
|
|
},
|
|
|
|
async fetchEntities(page) {
|
2022-12-10 14:17:18 -06:00
|
|
|
const startIndex = page * this.booksPerFetch
|
2021-12-04 19:56:29 -06:00
|
|
|
|
|
|
|
this.isFetchingEntities = true
|
|
|
|
|
|
|
|
if (!this.initialized) {
|
|
|
|
this.currentSFQueryString = this.buildSearchParams()
|
|
|
|
}
|
2022-03-23 17:59:14 -05:00
|
|
|
|
2022-12-10 14:17:18 -06:00
|
|
|
const entityPath = this.entityName === 'books' || this.entityName === 'series-books' ? `items` : this.entityName
|
|
|
|
const sfQueryString = this.currentSFQueryString ? this.currentSFQueryString + '&' : ''
|
2023-09-11 17:55:59 -05:00
|
|
|
const fullQueryString = `?${sfQueryString}limit=${this.booksPerFetch}&page=${page}&minified=1&include=rssfeed,numEpisodesIncomplete`
|
2021-12-04 19:56:29 -06:00
|
|
|
|
2023-09-15 17:35:44 -05:00
|
|
|
const payload = await this.$nativeHttp.get(`/api/libraries/${this.currentLibraryId}/${entityPath}${fullQueryString}`).catch((error) => {
|
2021-12-04 19:56:29 -06:00
|
|
|
console.error('failed to fetch books', error)
|
|
|
|
return null
|
|
|
|
})
|
2022-03-23 17:59:14 -05:00
|
|
|
|
2021-12-04 19:56:29 -06:00
|
|
|
this.isFetchingEntities = false
|
|
|
|
if (this.pendingReset) {
|
|
|
|
this.pendingReset = false
|
|
|
|
this.resetEntities()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (payload && payload.results) {
|
|
|
|
console.log('Received payload', payload)
|
|
|
|
if (!this.initialized) {
|
|
|
|
this.initialized = true
|
|
|
|
this.totalEntities = payload.total
|
|
|
|
this.totalShelves = Math.ceil(this.totalEntities / this.entitiesPerShelf)
|
|
|
|
this.entities = new Array(this.totalEntities)
|
|
|
|
this.$eventBus.$emit('bookshelf-total-entities', this.totalEntities)
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < payload.results.length; i++) {
|
2022-12-10 14:17:18 -06:00
|
|
|
const index = i + startIndex
|
2021-12-04 19:56:29 -06:00
|
|
|
this.entities[index] = payload.results[i]
|
|
|
|
if (this.entityComponentRefs[index]) {
|
|
|
|
this.entityComponentRefs[index].setEntity(this.entities[index])
|
2022-04-07 18:46:58 -05:00
|
|
|
|
|
|
|
if (this.isBookEntity) {
|
2022-12-10 14:17:18 -06:00
|
|
|
const localLibraryItem = this.localLibraryItems.find((lli) => lli.libraryItemId == this.entities[index].id)
|
2022-04-07 18:46:58 -05:00
|
|
|
if (localLibraryItem) {
|
|
|
|
this.entityComponentRefs[index].setLocalLibraryItem(localLibraryItem)
|
|
|
|
}
|
|
|
|
}
|
2021-12-04 19:56:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async loadPage(page) {
|
2022-04-04 19:08:27 -05:00
|
|
|
if (!this.currentLibraryId) {
|
|
|
|
console.error('[LazyBookshelf] loadPage current library id not set')
|
|
|
|
return
|
|
|
|
}
|
2021-12-04 19:56:29 -06:00
|
|
|
this.pagesLoaded[page] = true
|
|
|
|
await this.fetchEntities(page)
|
|
|
|
},
|
|
|
|
mountEntites(fromIndex, toIndex) {
|
|
|
|
for (let i = fromIndex; i < toIndex; i++) {
|
|
|
|
if (!this.entityIndexesMounted.includes(i)) {
|
|
|
|
this.cardsHelpers.mountEntityCard(i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
handleScroll(scrollTop) {
|
|
|
|
this.currScrollTop = scrollTop
|
|
|
|
var firstShelfIndex = Math.floor(scrollTop / this.shelfHeight)
|
|
|
|
var lastShelfIndex = Math.ceil((scrollTop + this.bookshelfHeight) / this.shelfHeight)
|
|
|
|
lastShelfIndex = Math.min(this.totalShelves - 1, lastShelfIndex)
|
|
|
|
|
|
|
|
var firstBookIndex = firstShelfIndex * this.entitiesPerShelf
|
|
|
|
var lastBookIndex = lastShelfIndex * this.entitiesPerShelf + this.entitiesPerShelf
|
|
|
|
lastBookIndex = Math.min(this.totalEntities, lastBookIndex)
|
|
|
|
|
|
|
|
var firstBookPage = Math.floor(firstBookIndex / this.booksPerFetch)
|
|
|
|
var lastBookPage = Math.floor(lastBookIndex / this.booksPerFetch)
|
|
|
|
if (!this.pagesLoaded[firstBookPage]) {
|
|
|
|
console.log('Must load next batch', firstBookPage, 'book index', firstBookIndex)
|
|
|
|
this.loadPage(firstBookPage)
|
|
|
|
}
|
|
|
|
if (!this.pagesLoaded[lastBookPage]) {
|
|
|
|
console.log('Must load last next batch', lastBookPage, 'book index', lastBookIndex)
|
|
|
|
this.loadPage(lastBookPage)
|
|
|
|
}
|
|
|
|
|
2022-04-07 18:46:58 -05:00
|
|
|
// Remove entities out of view
|
2021-12-04 19:56:29 -06:00
|
|
|
this.entityIndexesMounted = this.entityIndexesMounted.filter((_index) => {
|
|
|
|
if (_index < firstBookIndex || _index >= lastBookIndex) {
|
|
|
|
var el = document.getElementById(`book-card-${_index}`)
|
|
|
|
if (el) el.remove()
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
this.mountEntites(firstBookIndex, lastBookIndex)
|
|
|
|
},
|
|
|
|
destroyEntityComponents() {
|
|
|
|
for (const key in this.entityComponentRefs) {
|
|
|
|
if (this.entityComponentRefs[key] && this.entityComponentRefs[key].destroy) {
|
|
|
|
this.entityComponentRefs[key].destroy()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setDownloads() {
|
2021-12-05 18:31:47 -06:00
|
|
|
if (this.entityName === 'books') {
|
2022-04-04 19:08:27 -05:00
|
|
|
this.entities = []
|
2021-12-05 18:31:47 -06:00
|
|
|
// TOOD: Sort and filter here
|
|
|
|
this.totalEntities = this.entities.length
|
|
|
|
this.totalShelves = Math.ceil(this.totalEntities / this.entitiesPerShelf)
|
|
|
|
} else {
|
|
|
|
// TODO: Support offline series and collections
|
|
|
|
this.entities = []
|
|
|
|
this.totalEntities = 0
|
|
|
|
this.totalShelves = 0
|
|
|
|
}
|
2021-12-04 19:56:29 -06:00
|
|
|
this.$eventBus.$emit('bookshelf-total-entities', this.totalEntities)
|
|
|
|
},
|
|
|
|
async resetEntities() {
|
|
|
|
if (this.isFetchingEntities) {
|
|
|
|
this.pendingReset = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.destroyEntityComponents()
|
|
|
|
this.entityIndexesMounted = []
|
|
|
|
this.entityComponentRefs = {}
|
|
|
|
this.pagesLoaded = {}
|
|
|
|
this.entities = []
|
|
|
|
this.totalShelves = 0
|
|
|
|
this.totalEntities = 0
|
|
|
|
this.currentPage = 0
|
|
|
|
this.initialized = false
|
|
|
|
|
|
|
|
this.initSizeData()
|
2022-04-04 19:08:27 -05:00
|
|
|
if (this.user) {
|
2021-12-04 19:56:29 -06:00
|
|
|
await this.loadPage(0)
|
|
|
|
var lastBookIndex = Math.min(this.totalEntities, this.shelvesPerPage * this.entitiesPerShelf)
|
|
|
|
this.mountEntites(0, lastBookIndex)
|
|
|
|
} else {
|
2022-04-04 19:08:27 -05:00
|
|
|
// Local only
|
2021-12-04 19:56:29 -06:00
|
|
|
}
|
|
|
|
},
|
2021-12-05 18:31:47 -06:00
|
|
|
remountEntities() {
|
|
|
|
// Remount when an entity is removed
|
|
|
|
for (const key in this.entityComponentRefs) {
|
|
|
|
if (this.entityComponentRefs[key]) {
|
|
|
|
this.entityComponentRefs[key].destroy()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.entityComponentRefs = {}
|
|
|
|
this.entityIndexesMounted.forEach((i) => {
|
|
|
|
this.cardsHelpers.mountEntityCard(i)
|
|
|
|
})
|
|
|
|
},
|
2021-12-04 19:56:29 -06:00
|
|
|
initSizeData() {
|
|
|
|
var bookshelf = document.getElementById('bookshelf')
|
|
|
|
if (!bookshelf) {
|
|
|
|
console.error('Failed to init size data')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var entitiesPerShelfBefore = this.entitiesPerShelf
|
|
|
|
|
|
|
|
var { clientHeight, clientWidth } = bookshelf
|
|
|
|
this.bookshelfHeight = clientHeight
|
|
|
|
this.bookshelfWidth = clientWidth
|
2023-01-25 17:32:52 -06:00
|
|
|
this.entitiesPerShelf = Math.max(1, this.showBookshelfListView ? 1 : Math.floor((this.bookshelfWidth - 16) / this.totalEntityCardWidth))
|
2021-12-04 19:56:29 -06:00
|
|
|
this.shelvesPerPage = Math.ceil(this.bookshelfHeight / this.shelfHeight) + 2
|
|
|
|
this.bookshelfMarginLeft = (this.bookshelfWidth - this.entitiesPerShelf * this.totalEntityCardWidth) / 2
|
|
|
|
|
2022-07-01 17:01:40 -05:00
|
|
|
const entitiesPerPage = this.shelvesPerPage * this.entitiesPerShelf
|
|
|
|
this.booksPerFetch = Math.ceil(entitiesPerPage / 20) * 20 // Round up to the nearest 20
|
|
|
|
|
2021-12-04 19:56:29 -06:00
|
|
|
if (this.totalEntities) {
|
|
|
|
this.totalShelves = Math.ceil(this.totalEntities / this.entitiesPerShelf)
|
|
|
|
}
|
|
|
|
return entitiesPerShelfBefore < this.entitiesPerShelf // Books per shelf has changed
|
|
|
|
},
|
2021-12-05 18:31:47 -06:00
|
|
|
async init() {
|
2021-12-04 19:56:29 -06:00
|
|
|
if (this.isFirstInit) return
|
2023-09-17 10:23:35 -05:00
|
|
|
if (!this.user) {
|
|
|
|
// Offline support not available
|
|
|
|
await this.resetEntities()
|
|
|
|
this.$eventBus.$emit('bookshelf-total-entities', 0)
|
|
|
|
return
|
|
|
|
}
|
2022-04-07 18:46:58 -05:00
|
|
|
|
|
|
|
this.localLibraryItems = await this.$db.getLocalLibraryItems(this.currentLibraryMediaType)
|
|
|
|
console.log('Local library items loaded for lazy bookshelf', this.localLibraryItems.length)
|
|
|
|
|
2021-12-04 19:56:29 -06:00
|
|
|
this.isFirstInit = true
|
2021-12-05 18:31:47 -06:00
|
|
|
this.initSizeData()
|
2021-12-04 19:56:29 -06:00
|
|
|
await this.loadPage(0)
|
|
|
|
var lastBookIndex = Math.min(this.totalEntities, this.shelvesPerPage * this.entitiesPerShelf)
|
|
|
|
this.mountEntites(0, lastBookIndex)
|
2022-05-22 14:19:13 -05:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|
2021-12-04 19:56:29 -06:00
|
|
|
},
|
|
|
|
scroll(e) {
|
|
|
|
if (!e || !e.target) return
|
2022-04-04 19:08:27 -05:00
|
|
|
if (!this.user) return
|
2021-12-04 19:56:29 -06:00
|
|
|
var { scrollTop } = e.target
|
|
|
|
this.handleScroll(scrollTop)
|
|
|
|
},
|
|
|
|
buildSearchParams() {
|
2022-04-08 19:05:32 -05:00
|
|
|
if (this.page === 'search' || this.page === 'series' || this.page === 'collections') {
|
|
|
|
return ''
|
2021-12-04 19:56:29 -06:00
|
|
|
}
|
2022-04-08 19:05:32 -05:00
|
|
|
|
|
|
|
let searchParams = new URLSearchParams()
|
|
|
|
if (this.page === 'series-books') {
|
|
|
|
searchParams.set('filter', `series.${this.$encode(this.seriesId)}`)
|
2023-03-03 17:05:23 -06:00
|
|
|
if (this.collapseBookSeries) {
|
|
|
|
searchParams.set('collapseseries', 1)
|
|
|
|
}
|
2022-04-08 19:05:32 -05:00
|
|
|
} else {
|
|
|
|
if (this.filterBy && this.filterBy !== 'all') {
|
|
|
|
searchParams.set('filter', this.filterBy)
|
|
|
|
}
|
|
|
|
if (this.orderBy) {
|
|
|
|
searchParams.set('sort', this.orderBy)
|
|
|
|
searchParams.set('desc', this.orderDesc ? 1 : 0)
|
|
|
|
}
|
|
|
|
if (this.collapseSeries) {
|
|
|
|
searchParams.set('collapseseries', 1)
|
|
|
|
}
|
2021-12-04 19:56:29 -06:00
|
|
|
}
|
|
|
|
return searchParams.toString()
|
|
|
|
},
|
|
|
|
checkUpdateSearchParams() {
|
2023-01-17 17:47:29 -06:00
|
|
|
const newSearchParams = this.buildSearchParams()
|
|
|
|
let currentQueryString = window.location.search
|
2021-12-04 19:56:29 -06:00
|
|
|
if (currentQueryString && currentQueryString.startsWith('?')) currentQueryString = currentQueryString.slice(1)
|
|
|
|
|
2023-01-17 17:47:29 -06:00
|
|
|
if (newSearchParams === '' && !currentQueryString) {
|
2021-12-04 19:56:29 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (newSearchParams !== this.currentSFQueryString || newSearchParams !== currentQueryString) {
|
2023-01-17 17:47:29 -06:00
|
|
|
const queryString = newSearchParams ? `?${newSearchParams}` : ''
|
|
|
|
let newurl = window.location.protocol + '//' + window.location.host + window.location.pathname + queryString
|
2021-12-04 19:56:29 -06:00
|
|
|
window.history.replaceState({ path: newurl }, '', newurl)
|
2022-05-22 14:19:13 -05:00
|
|
|
|
|
|
|
this.routeFullPath = window.location.pathname + (window.location.search || '') // Update for saving scroll position
|
2021-12-04 19:56:29 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
},
|
|
|
|
settingsUpdated(settings) {
|
2023-01-17 17:47:29 -06:00
|
|
|
const wasUpdated = this.checkUpdateSearchParams()
|
2021-12-04 19:56:29 -06:00
|
|
|
if (wasUpdated) {
|
|
|
|
this.resetEntities()
|
|
|
|
}
|
|
|
|
},
|
2022-06-05 16:32:28 -05:00
|
|
|
libraryChanged() {
|
2023-01-11 17:29:49 -06:00
|
|
|
if (this.currentLibraryMediaType !== 'book' && (this.page === 'series' || this.page === 'collections' || this.page === 'series-books')) {
|
|
|
|
this.$router.replace('/bookshelf')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-04 19:56:29 -06:00
|
|
|
if (this.hasFilter) {
|
|
|
|
this.clearFilter()
|
|
|
|
} else {
|
|
|
|
this.resetEntities()
|
|
|
|
}
|
|
|
|
},
|
2022-03-23 17:59:14 -05:00
|
|
|
libraryItemAdded(libraryItem) {
|
|
|
|
console.log('libraryItem added', libraryItem)
|
|
|
|
// TODO: Check if item would be on this shelf
|
2021-12-05 18:31:47 -06:00
|
|
|
this.resetEntities()
|
|
|
|
},
|
2022-03-23 17:59:14 -05:00
|
|
|
libraryItemUpdated(libraryItem) {
|
|
|
|
console.log('Item updated', libraryItem)
|
2021-12-05 18:31:47 -06:00
|
|
|
if (this.entityName === 'books' || this.entityName === 'series-books') {
|
2022-03-23 17:59:14 -05:00
|
|
|
var indexOf = this.entities.findIndex((ent) => ent && ent.id === libraryItem.id)
|
2021-12-05 18:31:47 -06:00
|
|
|
if (indexOf >= 0) {
|
2022-03-23 17:59:14 -05:00
|
|
|
this.entities[indexOf] = libraryItem
|
2021-12-05 18:31:47 -06:00
|
|
|
if (this.entityComponentRefs[indexOf]) {
|
2022-03-23 17:59:14 -05:00
|
|
|
this.entityComponentRefs[indexOf].setEntity(libraryItem)
|
2022-04-07 18:46:58 -05:00
|
|
|
|
|
|
|
if (this.isBookEntity) {
|
|
|
|
var localLibraryItem = this.localLibraryItems.find((lli) => lli.libraryItemId == libraryItem.id)
|
|
|
|
if (localLibraryItem) {
|
|
|
|
this.entityComponentRefs[indexOf].setLocalLibraryItem(localLibraryItem)
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 18:31:47 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-03-23 17:59:14 -05:00
|
|
|
libraryItemRemoved(libraryItem) {
|
2021-12-05 18:31:47 -06:00
|
|
|
if (this.entityName === 'books' || this.entityName === 'series-books') {
|
2022-03-23 17:59:14 -05:00
|
|
|
var indexOf = this.entities.findIndex((ent) => ent && ent.id === libraryItem.id)
|
2021-12-05 18:31:47 -06:00
|
|
|
if (indexOf >= 0) {
|
2022-03-23 17:59:14 -05:00
|
|
|
this.entities = this.entities.filter((ent) => ent.id !== libraryItem.id)
|
2021-12-05 18:31:47 -06:00
|
|
|
this.totalEntities = this.entities.length
|
|
|
|
this.$eventBus.$emit('bookshelf-total-entities', this.totalEntities)
|
2022-03-23 17:59:14 -05:00
|
|
|
this.executeRebuild()
|
2021-12-05 18:31:47 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-03-23 17:59:14 -05:00
|
|
|
libraryItemsAdded(libraryItems) {
|
|
|
|
console.log('items added', libraryItems)
|
|
|
|
// TODO: Check if item would be on this shelf
|
2021-12-05 18:31:47 -06:00
|
|
|
this.resetEntities()
|
|
|
|
},
|
2022-03-23 17:59:14 -05:00
|
|
|
libraryItemsUpdated(libraryItems) {
|
|
|
|
libraryItems.forEach((ab) => {
|
|
|
|
this.libraryItemUpdated(ab)
|
2021-12-05 18:31:47 -06:00
|
|
|
})
|
|
|
|
},
|
2023-02-25 16:53:48 -06:00
|
|
|
screenOrientationChange() {
|
|
|
|
setTimeout(() => {
|
|
|
|
console.log('LazyBookshelf Screen orientation change')
|
|
|
|
this.resetEntities()
|
|
|
|
}, 50)
|
|
|
|
},
|
2021-12-04 19:56:29 -06:00
|
|
|
initListeners() {
|
2023-01-29 16:04:03 -06:00
|
|
|
const bookshelf = document.getElementById('bookshelf-wrapper')
|
2021-12-04 19:56:29 -06:00
|
|
|
if (bookshelf) {
|
|
|
|
bookshelf.addEventListener('scroll', this.scroll)
|
|
|
|
}
|
2022-03-23 17:59:14 -05:00
|
|
|
|
2021-12-04 19:56:29 -06:00
|
|
|
this.$eventBus.$on('library-changed', this.libraryChanged)
|
2022-12-17 14:48:56 -06:00
|
|
|
this.$eventBus.$on('user-settings', this.settingsUpdated)
|
2021-12-04 19:56:29 -06:00
|
|
|
|
2022-04-04 19:08:27 -05:00
|
|
|
this.$socket.$on('item_updated', this.libraryItemUpdated)
|
|
|
|
this.$socket.$on('item_added', this.libraryItemAdded)
|
|
|
|
this.$socket.$on('item_removed', this.libraryItemRemoved)
|
|
|
|
this.$socket.$on('items_updated', this.libraryItemsUpdated)
|
|
|
|
this.$socket.$on('items_added', this.libraryItemsAdded)
|
2023-02-25 16:53:48 -06:00
|
|
|
|
|
|
|
if (screen.orientation) {
|
|
|
|
// Not available on ios
|
|
|
|
screen.orientation.addEventListener('change', this.screenOrientationChange)
|
|
|
|
} else {
|
|
|
|
document.addEventListener('orientationchange', this.screenOrientationChange)
|
|
|
|
}
|
2021-12-04 19:56:29 -06:00
|
|
|
},
|
|
|
|
removeListeners() {
|
2023-01-29 16:04:03 -06:00
|
|
|
const bookshelf = document.getElementById('bookshelf-wrapper')
|
2021-12-04 19:56:29 -06:00
|
|
|
if (bookshelf) {
|
|
|
|
bookshelf.removeEventListener('scroll', this.scroll)
|
|
|
|
}
|
2022-03-23 17:59:14 -05:00
|
|
|
|
2021-12-04 19:56:29 -06:00
|
|
|
this.$eventBus.$off('library-changed', this.libraryChanged)
|
2022-12-17 14:48:56 -06:00
|
|
|
this.$eventBus.$off('user-settings', this.settingsUpdated)
|
2021-12-04 19:56:29 -06:00
|
|
|
|
2022-04-04 19:08:27 -05:00
|
|
|
this.$socket.$off('item_updated', this.libraryItemUpdated)
|
|
|
|
this.$socket.$off('item_added', this.libraryItemAdded)
|
|
|
|
this.$socket.$off('item_removed', this.libraryItemRemoved)
|
|
|
|
this.$socket.$off('items_updated', this.libraryItemsUpdated)
|
|
|
|
this.$socket.$off('items_added', this.libraryItemsAdded)
|
2023-02-25 16:53:48 -06:00
|
|
|
|
|
|
|
if (screen.orientation) {
|
|
|
|
// Not available on ios
|
|
|
|
screen.orientation.removeEventListener('change', this.screenOrientationChange)
|
|
|
|
} else {
|
|
|
|
document.removeEventListener('orientationchange', this.screenOrientationChange)
|
|
|
|
}
|
2021-12-04 19:56:29 -06:00
|
|
|
}
|
|
|
|
},
|
2022-05-22 14:19:13 -05:00
|
|
|
updated() {
|
|
|
|
this.routeFullPath = window.location.pathname + (window.location.search || '')
|
|
|
|
},
|
2021-12-04 19:56:29 -06:00
|
|
|
mounted() {
|
2022-05-22 14:19:13 -05:00
|
|
|
this.routeFullPath = window.location.pathname + (window.location.search || '')
|
|
|
|
|
2022-04-04 19:08:27 -05:00
|
|
|
this.init()
|
2021-12-04 19:56:29 -06:00
|
|
|
this.initListeners()
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.removeListeners()
|
2022-05-22 14:19:13 -05:00
|
|
|
|
|
|
|
// 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 })
|
|
|
|
}
|
2021-12-04 19:56:29 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|