diff --git a/components/bookshelf/LazyBookshelf.vue b/components/bookshelf/LazyBookshelf.vue index ae352f8d..3fd0aaf0 100644 --- a/components/bookshelf/LazyBookshelf.vue +++ b/components/bookshelf/LazyBookshelf.vue @@ -134,7 +134,7 @@ export default { return this.$store.getters['getAltViewEnabled'] }, sizeMultiplier() { - var baseSize = this.isCoverSquareAspectRatio ? 192 : 120 + const baseSize = this.isCoverSquareAspectRatio ? 192 : 120 return this.entityWidth / baseSize } }, @@ -145,7 +145,7 @@ export default { }) }, async fetchEntities(page) { - var startIndex = page * this.booksPerFetch + const startIndex = page * this.booksPerFetch this.isFetchingEntities = true @@ -153,11 +153,11 @@ export default { this.currentSFQueryString = this.buildSearchParams() } - var entityPath = this.entityName === 'books' || this.entityName === 'series-books' ? `items` : this.entityName - var sfQueryString = this.currentSFQueryString ? this.currentSFQueryString + '&' : '' - var fullQueryString = `?${sfQueryString}limit=${this.booksPerFetch}&page=${page}&minified=1` + const entityPath = this.entityName === 'books' || this.entityName === 'series-books' ? `items` : this.entityName + const sfQueryString = this.currentSFQueryString ? this.currentSFQueryString + '&' : '' + const fullQueryString = `?${sfQueryString}limit=${this.booksPerFetch}&page=${page}&minified=1` - var payload = await this.$axios.$get(`/api/libraries/${this.currentLibraryId}/${entityPath}${fullQueryString}`).catch((error) => { + const payload = await this.$axios.$get(`/api/libraries/${this.currentLibraryId}/${entityPath}${fullQueryString}`).catch((error) => { console.error('failed to fetch books', error) return null }) @@ -179,13 +179,13 @@ export default { } for (let i = 0; i < payload.results.length; i++) { - var index = i + startIndex + const index = i + startIndex this.entities[index] = payload.results[i] if (this.entityComponentRefs[index]) { this.entityComponentRefs[index].setEntity(this.entities[index]) if (this.isBookEntity) { - var localLibraryItem = this.localLibraryItems.find((lli) => lli.libraryItemId == this.entities[index].id) + const localLibraryItem = this.localLibraryItems.find((lli) => lli.libraryItemId == this.entities[index].id) if (localLibraryItem) { this.entityComponentRefs[index].setLocalLibraryItem(localLibraryItem) } diff --git a/pages/bookshelf/index.vue b/pages/bookshelf/index.vue index 0806ca74..95e7f452 100644 --- a/pages/bookshelf/index.vue +++ b/pages/bookshelf/index.vue @@ -41,12 +41,19 @@ export default { localLibraryItems: [] } }, + watch: { + networkConnected(newVal) { + // Update shelves when network connect status changes + console.log(`Network changed to ${newVal} - fetch categories`) + this.fetchCategories() + } + }, computed: { user() { return this.$store.state.user.user }, - isSocketConnected() { - return this.$store.state.socketConnected + networkConnected() { + return this.$store.state.networkConnected }, currentLibraryName() { return this.$store.getters['libraries/getCurrentLibraryName'] @@ -54,6 +61,9 @@ export default { currentLibraryId() { return this.$store.state.libraries.currentLibraryId }, + currentLibraryMediaType() { + return this.$store.getters['libraries/getCurrentLibraryMediaType'] + }, altViewEnabled() { return this.$store.getters['getAltViewEnabled'] }, @@ -111,21 +121,19 @@ export default { this.shelves = [] this.localLibraryItems = await this.$db.getLocalLibraryItems() - - var localCategories = await this.getLocalMediaItemCategories() - this.shelves = this.shelves.concat(localCategories) + const localCategories = await this.getLocalMediaItemCategories() if (this.user && this.currentLibraryId) { - var categories = await this.$axios.$get(`/api/libraries/${this.currentLibraryId}/personalized?minified=1`).catch((error) => { + const categories = await this.$axios.$get(`/api/libraries/${this.currentLibraryId}/personalized?minified=1`).catch((error) => { console.error('Failed to fetch categories', error) return [] }) - categories = categories.map((cat) => { + this.shelves = categories.map((cat) => { console.log('[breadcrumb] Personalized category from server', cat.type) if (cat.type == 'book' || cat.type == 'podcast' || cat.type == 'episode') { // Map localLibraryItem to entities cat.entities = cat.entities.map((entity) => { - var localLibraryItem = this.localLibraryItems.find((lli) => { + const localLibraryItem = this.localLibraryItems.find((lli) => { return lli.libraryItemId == entity.id }) if (localLibraryItem) { @@ -136,14 +144,15 @@ export default { } return cat }) - // Put continue listening shelf first - var continueListeningShelf = categories.find((c) => c.id == 'continue-listening') - if (continueListeningShelf) { - this.shelves = [continueListeningShelf, ...this.shelves] - console.log(this.shelves) - } - this.shelves = this.shelves.concat(categories.filter((c) => c.id != 'continue-listening')) + + // Only add the local shelf with the same media type + const localShelves = localCategories.filter((cat) => cat.type === this.currentLibraryMediaType) + this.shelves.push(...localShelves) + } else { + // Offline only local + this.shelves = localCategories } + this.loading = false }, async libraryChanged() { @@ -195,21 +204,14 @@ export default { }, initListeners() { this.$eventBus.$on('library-changed', this.libraryChanged) - // this.$eventBus.$on('downloads-loaded', this.downloadsLoaded) }, removeListeners() { this.$eventBus.$off('library-changed', this.libraryChanged) - // this.$eventBus.$off('downloads-loaded', this.downloadsLoaded) } }, mounted() { this.initListeners() this.fetchCategories() - // if (this.$server.initialized && this.currentLibraryId) { - // this.fetchCategories() - // } else { - // this.shelves = this.downloadOnlyShelves - // } }, beforeDestroy() { this.removeListeners()