No {{ entityName }}
Clear Filter
@@ -121,8 +116,17 @@ export default {
// Includes margin
return this.entityWidth + 24
},
+ downloads() {
+ return this.$store.getters['downloads/getDownloads']
+ },
downloadedBooks() {
- return this.$store.getters['downloads/getAudiobooks']
+ return this.downloads.map((dl) => {
+ var download = { ...dl }
+ var ab = { ...download.audiobook }
+ delete download.audiobook
+ ab.download = download
+ return ab
+ })
}
},
methods: {
@@ -169,6 +173,16 @@ export default {
}
for (let i = 0; i < payload.results.length; i++) {
+ if (this.entityName === 'books' || this.entityName === 'series-books') {
+ // Check if has download and append download obj
+ var download = this.downloads.find((dl) => dl.id === payload.results[i].id)
+ if (download) {
+ var dl = { ...download }
+ delete dl.audiobook
+ payload.results[i].download = dl
+ }
+ }
+
var index = i + startIndex
this.entities[index] = payload.results[i]
if (this.entityComponentRefs[index]) {
@@ -227,12 +241,17 @@ export default {
}
},
setDownloads() {
- // TODO: Check entityName
- this.entities = this.downloadedBooks.map((db) => ({ ...db }))
- // TOOD: Sort and filter here
- this.totalEntities = this.entities.length
- this.totalShelves = Math.ceil(this.totalEntities / this.entitiesPerShelf)
- this.entities = new Array(this.totalEntities)
+ if (this.entityName === 'books') {
+ this.entities = this.downloadedBooks
+ // 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
+ }
this.$eventBus.$emit('bookshelf-total-entities', this.totalEntities)
},
async resetEntities() {
@@ -257,9 +276,22 @@ export default {
this.mountEntites(0, lastBookIndex)
} else {
this.setDownloads()
+
this.mountEntites(0, this.totalEntities - 1)
}
},
+ 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)
+ })
+ },
initSizeData() {
var bookshelf = document.getElementById('bookshelf')
if (!bookshelf) {
@@ -282,15 +314,23 @@ export default {
}
return entitiesPerShelfBefore < this.entitiesPerShelf // Books per shelf has changed
},
- async init(bookshelf) {
+ async init() {
if (this.isFirstInit) return
this.isFirstInit = true
- this.initSizeData(bookshelf)
+ this.initSizeData()
await this.loadPage(0)
var lastBookIndex = Math.min(this.totalEntities, this.shelvesPerPage * this.entitiesPerShelf)
this.mountEntites(0, lastBookIndex)
},
+ initDownloads() {
+ this.initSizeData()
+ this.setDownloads()
+ this.$nextTick(() => {
+ console.log('Mounting downloads', this.totalEntities, 'total shelves', this.totalShelves)
+ this.mountEntites(0, this.totalEntities)
+ })
+ },
scroll(e) {
if (!e || !e.target) return
if (!this.isSocketConnected) return // Offline books are all mounted at once
@@ -345,6 +385,49 @@ export default {
this.resetEntities()
}
},
+ downloadsLoaded() {
+ if (!this.isSocketConnected) {
+ this.resetEntities()
+ }
+ },
+ audiobookAdded(audiobook) {
+ console.log('Audiobook added', audiobook)
+ // TODO: Check if audiobook would be on this shelf
+ this.resetEntities()
+ },
+ audiobookUpdated(audiobook) {
+ console.log('Audiobook updated', audiobook)
+ if (this.entityName === 'books' || this.entityName === 'series-books') {
+ var indexOf = this.entities.findIndex((ent) => ent && ent.id === audiobook.id)
+ if (indexOf >= 0) {
+ this.entities[indexOf] = audiobook
+ if (this.entityComponentRefs[indexOf]) {
+ this.entityComponentRefs[indexOf].setEntity(audiobook)
+ }
+ }
+ }
+ },
+ audiobookRemoved(audiobook) {
+ if (this.entityName === 'books' || this.entityName === 'series-books') {
+ var indexOf = this.entities.findIndex((ent) => ent && ent.id === audiobook.id)
+ if (indexOf >= 0) {
+ this.entities = this.entities.filter((ent) => ent.id !== audiobook.id)
+ this.totalEntities = this.entities.length
+ this.$eventBus.$emit('bookshelf-total-entities', this.totalEntities)
+ this.remountEntities()
+ }
+ }
+ },
+ audiobooksAdded(audiobooks) {
+ console.log('audiobooks added', audiobooks)
+ // TODO: Check if audiobook would be on this shelf
+ this.resetEntities()
+ },
+ audiobooksUpdated(audiobooks) {
+ audiobooks.forEach((ab) => {
+ this.audiobookUpdated(ab)
+ })
+ },
initListeners() {
var bookshelf = document.getElementById('bookshelf-wrapper')
if (bookshelf) {
@@ -354,17 +437,18 @@ export default {
// this.$eventBus.$on('bookshelf-select-all', this.selectAllEntities)
// this.$eventBus.$on('bookshelf-keyword-filter', this.updateKeywordFilter)
this.$eventBus.$on('library-changed', this.libraryChanged)
+ this.$eventBus.$on('downloads-loaded', this.downloadsLoaded)
this.$store.commit('user/addSettingsListener', { id: 'lazy-bookshelf', meth: this.settingsUpdated })
- // if (this.$root.socket) {
- // this.$root.socket.on('audiobook_updated', this.audiobookUpdated)
- // this.$root.socket.on('audiobook_added', this.audiobookAdded)
- // this.$root.socket.on('audiobook_removed', this.audiobookRemoved)
- // this.$root.socket.on('audiobooks_updated', this.audiobooksUpdated)
- // this.$root.socket.on('audiobooks_added', this.audiobooksAdded)
- // } else {
- // console.error('Bookshelf - Socket not initialized')
- // }
+ if (this.$server.socket) {
+ this.$server.socket.on('audiobook_updated', this.audiobookUpdated)
+ this.$server.socket.on('audiobook_added', this.audiobookAdded)
+ this.$server.socket.on('audiobook_removed', this.audiobookRemoved)
+ this.$server.socket.on('audiobooks_updated', this.audiobooksUpdated)
+ this.$server.socket.on('audiobooks_added', this.audiobooksAdded)
+ } else {
+ console.error('Bookshelf - Socket not initialized')
+ }
},
removeListeners() {
var bookshelf = document.getElementById('bookshelf-wrapper')
@@ -372,22 +456,25 @@ export default {
bookshelf.removeEventListener('scroll', this.scroll)
}
this.$eventBus.$off('library-changed', this.libraryChanged)
+ this.$eventBus.$off('downloads-loaded', this.downloadsLoaded)
this.$store.commit('user/removeSettingsListener', 'lazy-bookshelf')
- // if (this.$root.socket) {
- // this.$root.socket.off('audiobook_updated', this.audiobookUpdated)
- // this.$root.socket.off('audiobook_added', this.audiobookAdded)
- // this.$root.socket.off('audiobook_removed', this.audiobookRemoved)
- // this.$root.socket.off('audiobooks_updated', this.audiobooksUpdated)
- // this.$root.socket.off('audiobooks_added', this.audiobooksAdded)
- // } else {
- // console.error('Bookshelf - Socket not initialized')
- // }
+ if (this.$server.socket) {
+ this.$server.socket.off('audiobook_updated', this.audiobookUpdated)
+ this.$server.socket.off('audiobook_added', this.audiobookAdded)
+ this.$server.socket.off('audiobook_removed', this.audiobookRemoved)
+ this.$server.socket.off('audiobooks_updated', this.audiobooksUpdated)
+ this.$server.socket.off('audiobooks_added', this.audiobooksAdded)
+ } else {
+ console.error('Bookshelf - Socket not initialized')
+ }
}
},
mounted() {
if (this.$server.initialized) {
this.init()
+ } else {
+ this.initDownloads()
}
this.$server.on('initialized', this.socketInit)
this.initListeners()
diff --git a/components/bookshelf/LibraryShelf.vue b/components/bookshelf/LibraryShelf.vue
deleted file mode 100644
index 807eda58..00000000
--- a/components/bookshelf/LibraryShelf.vue
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
diff --git a/components/bookshelf/Shelf.vue b/components/bookshelf/Shelf.vue
index 41cef813..49abc225 100644
--- a/components/bookshelf/Shelf.vue
+++ b/components/bookshelf/Shelf.vue
@@ -2,7 +2,6 @@
-
diff --git a/components/cards/BookCard.vue b/components/cards/BookCard.vue
deleted file mode 100644
index 073aaf44..00000000
--- a/components/cards/BookCard.vue
+++ /dev/null
@@ -1,95 +0,0 @@
-
-
-
-
-
-
-
-
- download_done
-
-
-
-
-
- priority_high
-
-
-
-
-
-
-
-
diff --git a/components/cards/BookCover.vue b/components/cards/BookCover.vue
deleted file mode 100644
index 5c3879b9..00000000
--- a/components/cards/BookCover.vue
+++ /dev/null
@@ -1,167 +0,0 @@
-
-
-
-
-
![]()
-
-
-
-
-

-
Invalid Cover
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/components/cards/CollectionCard.vue b/components/cards/CollectionCard.vue
deleted file mode 100644
index 8626d71d..00000000
--- a/components/cards/CollectionCard.vue
+++ /dev/null
@@ -1,86 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/components/cards/CollectionCover.vue b/components/cards/CollectionCover.vue
deleted file mode 100644
index 7ecb98cf..00000000
--- a/components/cards/CollectionCover.vue
+++ /dev/null
@@ -1,63 +0,0 @@
-
-
-
-
-
-
-
![]()
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/components/cards/LazyBookCard.vue b/components/cards/LazyBookCard.vue
index 2c3b5ecf..7d35616c 100644
--- a/components/cards/LazyBookCard.vue
+++ b/components/cards/LazyBookCard.vue
@@ -23,6 +23,12 @@
+
+
+ download_done
+
+
+
@@ -74,7 +80,15 @@ export default {
placeholderUrl() {
return '/book_placeholder.jpg'
},
+ hasDownload() {
+ return !!this._audiobook.download
+ },
+ downloadedCover() {
+ if (!this._audiobook.download) return null
+ return this._audiobook.download.cover
+ },
bookCoverSrc() {
+ if (this.downloadedCover) return this.downloadedCover
return this.store.getters['audiobooks/getBookCoverSrc'](this._audiobook, this.placeholderUrl)
},
audiobookId() {
@@ -96,7 +110,7 @@ export default {
return this.bookCoverAspectRatio === 1
},
sizeMultiplier() {
- var baseSize = this.squareAspectRatio ? 192 : 120
+ var baseSize = this.squareAspectRatio ? 160 : 100
return this.width / baseSize
},
title() {
diff --git a/components/cards/PlayerBookCover.vue b/components/cards/PlayerBookCover.vue
deleted file mode 100644
index 5c33c89b..00000000
--- a/components/cards/PlayerBookCover.vue
+++ /dev/null
@@ -1,167 +0,0 @@
-
-
-
-
-
![]()
-
-
-
-
-

-
Invalid Cover
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/components/cards/SeriesCard.vue b/components/cards/SeriesCard.vue
deleted file mode 100644
index 020af63c..00000000
--- a/components/cards/SeriesCard.vue
+++ /dev/null
@@ -1,113 +0,0 @@
-
-
-
-
-
-
-
-
{{ bookItems.length }}
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/components/cards/SeriesCover.vue b/components/cards/SeriesCover.vue
deleted file mode 100644
index f6277d27..00000000
--- a/components/cards/SeriesCover.vue
+++ /dev/null
@@ -1,171 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/components/home/BookshelfToolbar.vue b/components/home/BookshelfToolbar.vue
index 82fd5dbe..8bde454d 100644
--- a/components/home/BookshelfToolbar.vue
+++ b/components/home/BookshelfToolbar.vue
@@ -9,7 +9,7 @@
{{ selectedSeriesName }} ({{ totalEntities }})
- {{ viewIcon }}
+
filter_alt
diff --git a/components/modals/SearchModal.vue b/components/modals/SearchModal.vue
deleted file mode 100644
index e4ca742b..00000000
--- a/components/modals/SearchModal.vue
+++ /dev/null
@@ -1,100 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
{{ item.data.book.title }}
-
{{ item.data.book.author }}
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/components/tables/collection/BookTableRow.vue b/components/tables/collection/BookTableRow.vue
index 8e8afee3..704564de 100644
--- a/components/tables/collection/BookTableRow.vue
+++ b/components/tables/collection/BookTableRow.vue
@@ -1,8 +1,8 @@
-
-
+
+
@@ -38,6 +38,13 @@ export default {
}
},
computed: {
+ bookCoverAspectRatio() {
+ return this.$store.getters['getBookCoverAspectRatio']
+ },
+ bookWidth() {
+ if (this.bookCoverAspectRatio === 1) return 80
+ return 50
+ },
_book() {
return this.book.book || {}
},
diff --git a/layouts/default.vue b/layouts/default.vue
index c3654f64..b39dffa4 100644
--- a/layouts/default.vue
+++ b/layouts/default.vue
@@ -53,9 +53,13 @@ export default {
console.log('[Default] Connected socket sync user ab data')
this.$store.dispatch('user/syncUserAudiobookData')
+ this.initSocketListeners()
+
// Load libraries
this.$store.dispatch('libraries/load')
this.$store.dispatch('libraries/fetch', this.currentLibraryId)
+ } else {
+ this.removeSocketListeners()
}
},
socketConnectionFailed(err) {
@@ -260,18 +264,13 @@ export default {
this.onDownloadProgress(data)
})
- // var downloads = (await this.$sqlStore.getAllDownloads()) || []
var downloads = await this.$store.dispatch('downloads/loadFromStorage')
var downloadFolder = await this.$localStore.getDownloadFolder()
if (downloadFolder) {
await this.syncDownloads(downloads, downloadFolder)
}
-
- var userSavedSettings = await this.$localStore.getUserSettings()
- if (userSavedSettings) {
- this.$store.commit('user/setSettings', userSavedSettings)
- }
+ this.$eventBus.$emit('downloads-loaded')
var checkPermission = await StorageManager.checkStoragePermission()
console.log('Storage Permission is' + checkPermission.value)
@@ -282,6 +281,20 @@ export default {
this.$store.commit('setHasStoragePermission', true)
}
},
+ async loadSavedSettings() {
+ var userSavedServerSettings = await this.$localStore.getServerSettings()
+ if (userSavedServerSettings) {
+ this.$store.commit('setServerSettings', userSavedServerSettings)
+ }
+
+ var userSavedSettings = await this.$localStore.getUserSettings()
+ if (userSavedSettings) {
+ this.$store.commit('user/setSettings', userSavedSettings)
+ }
+
+ console.log('Loading offline user audiobook data')
+ await this.$store.dispatch('user/loadOfflineUserAudiobookData')
+ },
showErrorToast(message) {
this.$toast.error(message)
},
@@ -311,6 +324,53 @@ export default {
}
}
}
+ },
+ audiobookAdded(audiobook) {
+ this.$store.commit('libraries/updateFilterDataWithAudiobook', audiobook)
+ },
+ audiobookUpdated(audiobook) {
+ this.$store.commit('libraries/updateFilterDataWithAudiobook', audiobook)
+ },
+ audiobookRemoved(audiobook) {
+ if (this.$route.name.startsWith('audiobook')) {
+ if (this.$route.params.id === audiobook.id) {
+ this.$router.replace(`/bookshelf`)
+ }
+ }
+ },
+ audiobooksAdded(audiobooks) {
+ audiobooks.forEach((ab) => {
+ this.audiobookAdded(ab)
+ })
+ },
+ audiobooksUpdated(audiobooks) {
+ audiobooks.forEach((ab) => {
+ this.audiobookUpdated(ab)
+ })
+ },
+ userLoggedOut() {
+ // Only cancels stream if streamining not playing downloaded
+ this.$eventBus.$emit('close_stream')
+ },
+ initSocketListeners() {
+ if (this.$server.socket) {
+ // Audiobook Listeners
+ this.$server.socket.on('audiobook_updated', this.audiobookUpdated)
+ this.$server.socket.on('audiobook_added', this.audiobookAdded)
+ this.$server.socket.on('audiobook_removed', this.audiobookRemoved)
+ this.$server.socket.on('audiobooks_updated', this.audiobooksUpdated)
+ this.$server.socket.on('audiobooks_added', this.audiobooksAdded)
+ }
+ },
+ removeSocketListeners() {
+ if (this.$server.socket) {
+ // Audiobook Listeners
+ this.$server.socket.off('audiobook_updated', this.audiobookUpdated)
+ this.$server.socket.off('audiobook_added', this.audiobookAdded)
+ this.$server.socket.off('audiobook_removed', this.audiobookRemoved)
+ this.$server.socket.off('audiobooks_updated', this.audiobooksUpdated)
+ this.$server.socket.off('audiobooks_added', this.audiobooksAdded)
+ }
}
},
async mounted() {
@@ -321,6 +381,7 @@ export default {
console.log('Syncing on default mount')
this.$store.dispatch('user/syncUserAudiobookData')
}
+ this.$server.on('logout', this.userLoggedOut)
this.$server.on('connected', this.connected)
this.$server.on('connectionFailed', this.socketConnectionFailed)
this.$server.on('initialStream', this.initialStream)
@@ -333,6 +394,7 @@ export default {
await this.$store.dispatch('setupNetworkListener')
this.attemptConnection()
this.checkForUpdate()
+ this.loadSavedSettings()
this.initMediaStore()
}
},
@@ -341,7 +403,8 @@ export default {
console.error('No Server beforeDestroy')
return
}
-
+ this.removeSocketListeners()
+ this.$server.off('logout', this.userLoggedOut)
this.$server.off('connected', this.connected)
this.$server.off('connectionFailed', this.socketConnectionFailed)
this.$server.off('initialStream', this.initialStream)
diff --git a/mixins/bookshelfCardsHelpers.js b/mixins/bookshelfCardsHelpers.js
index 0df1c072..0a66cc7a 100644
--- a/mixins/bookshelfCardsHelpers.js
+++ b/mixins/bookshelfCardsHelpers.js
@@ -21,7 +21,7 @@ export default {
var shelf = Math.floor(index / this.entitiesPerShelf)
var shelfEl = document.getElementById(`shelf-${shelf}`)
if (!shelfEl) {
- console.error('invalid shelf', shelf, 'book index', index)
+ console.error('mount entity card invalid shelf', shelf, 'book index', index)
return
}
this.entityIndexesMounted.push(index)
@@ -43,7 +43,9 @@ export default {
}
var shelfOffsetY = this.isBookEntity ? 24 : 16
var row = index % this.entitiesPerShelf
- var shelfOffsetX = row * this.totalEntityCardWidth + this.bookshelfMarginLeft
+
+ var marginShiftLeft = 12
+ var shelfOffsetX = row * this.totalEntityCardWidth + this.bookshelfMarginLeft + marginShiftLeft
var ComponentClass = this.getComponentClass()
var props = {
@@ -67,10 +69,10 @@ export default {
}
})
this.entityComponentRefs[index] = instance
-
instance.$mount()
instance.$el.style.transform = `translate3d(${shelfOffsetX}px, ${shelfOffsetY}px, 0px)`
- instance.$el.classList.add('absolute', 'top-0', 'left-0', 'mx-3')
+
+ instance.$el.classList.add('absolute', 'top-0', 'left-0')
shelfEl.appendChild(instance.$el)
if (this.entities[index]) {
diff --git a/pages/account.vue b/pages/account.vue
index e026f5d3..25e5d011 100644
--- a/pages/account.vue
+++ b/pages/account.vue
@@ -80,9 +80,6 @@ export default {
})
this.$server.logout()
this.$router.push('/connect')
-
- this.$store.commit('audiobooks/reset')
- this.$store.dispatch('audiobooks/useDownloaded')
},
openAppStore() {
AppUpdate.openAppStore()
diff --git a/pages/audiobook/_id/index.vue b/pages/audiobook/_id/index.vue
index a50275db..88d88d00 100644
--- a/pages/audiobook/_id/index.vue
+++ b/pages/audiobook/_id/index.vue
@@ -3,8 +3,8 @@
{{ numTracks }} Tracks
@@ -64,7 +64,10 @@ export default {
return false
})
} else {
- audiobook = store.getters['audiobooks/getAudiobook'](audiobookId)
+ var download = store.getters['downloads/getDownload'](audiobookId)
+ if (download) {
+ audiobook = download.audiobook
+ }
}
if (!audiobook) {
@@ -84,6 +87,9 @@ export default {
isConnected() {
return this.$store.state.socketConnected
},
+ bookCoverAspectRatio() {
+ return this.$store.getters['getBookCoverAspectRatio']
+ },
audiobookId() {
return this.audiobook.id
},
@@ -116,34 +122,20 @@ export default {
size() {
return this.audiobook.size
},
- userAudiobooks() {
- return this.$store.state.user.user ? this.$store.state.user.user.audiobooks || {} : {}
- },
userAudiobook() {
- return this.userAudiobooks[this.audiobookId] || null
+ return this.$store.getters['user/getUserAudiobook'](this.audiobookId)
},
userToken() {
return this.$store.getters['user/getToken']
},
- localUserAudiobooks() {
- return this.$store.state.user.localUserAudiobooks || {}
- },
- localUserAudiobook() {
- return this.localUserAudiobooks[this.audiobookId] || null
- },
- mostRecentUserAudiobook() {
- if (!this.localUserAudiobook) return this.userAudiobook
- if (!this.userAudiobook) return this.localUserAudiobook
- return this.localUserAudiobook.lastUpdate > this.userAudiobook.lastUpdate ? this.localUserAudiobook : this.userAudiobook
- },
userCurrentTime() {
- return this.mostRecentUserAudiobook ? this.mostRecentUserAudiobook.currentTime : 0
+ return this.userAudiobook ? this.userAudiobook.currentTime : 0
},
userTimeRemaining() {
return this.duration - this.userCurrentTime
},
progressPercent() {
- return this.mostRecentUserAudiobook ? this.mostRecentUserAudiobook.progress : 0
+ return this.userAudiobook ? this.userAudiobook.progress : 0
},
isStreaming() {
return this.$store.getters['isAudiobookStreaming'](this.audiobookId)
@@ -242,16 +234,18 @@ export default {
this.resettingProgress = false
}
},
- audiobookUpdated() {
- console.log('Audiobook Updated - Fetch full audiobook')
- this.$axios
- .$get(`/api/books/${this.audiobookId}`)
- .then((audiobook) => {
- this.audiobook = audiobook
- })
- .catch((error) => {
- console.error('Failed', error)
- })
+ audiobookUpdated(audiobook) {
+ if (audiobook.id === this.audiobookId) {
+ console.log('Audiobook Updated - Fetch full audiobook')
+ this.$axios
+ .$get(`/api/books/${this.audiobookId}`)
+ .then((audiobook) => {
+ this.audiobook = audiobook
+ })
+ .catch((error) => {
+ console.error('Failed', error)
+ })
+ }
},
downloadClick() {
console.log('downloadClick ' + this.$server.connected + ' | ' + !!this.downloadObj)
@@ -427,9 +421,8 @@ export default {
this.$server.socket.on('download_ready', this.downloadReady)
this.$server.socket.on('download_killed', this.downloadKilled)
this.$server.socket.on('download_failed', this.downloadFailed)
+ this.$server.socket.on('audiobook_updated', this.audiobookUpdated)
}
-
- this.$store.commit('audiobooks/addListener', { id: 'audiobook', audiobookId: this.audiobookId, meth: this.audiobookUpdated })
},
beforeDestroy() {
if (!this.$server.socket) {
@@ -438,9 +431,8 @@ export default {
this.$server.socket.off('download_ready', this.downloadReady)
this.$server.socket.off('download_killed', this.downloadKilled)
this.$server.socket.off('download_failed', this.downloadFailed)
+ this.$server.socket.off('audiobook_updated', this.audiobookUpdated)
}
-
- this.$store.commit('audiobooks/removeListener', 'audiobook')
}
}
\ No newline at end of file
diff --git a/pages/bookshelf.vue b/pages/bookshelf.vue
index 26a6e1be..179a75d0 100644
--- a/pages/bookshelf.vue
+++ b/pages/bookshelf.vue
@@ -20,38 +20,7 @@ export default {
computed: {
isHome() {
return this.$route.name === 'bookshelf'
- },
- currentLibrary() {
- return this.$store.getters['libraries/getCurrentLibrary']
- },
- currentLibraryName() {
- return this.currentLibrary ? this.currentLibrary.name : 'Main'
- },
- isSocketConnected() {
- return this.$store.state.socketConnected
}
- },
- methods: {
- async loadCollections() {
- this.$store.dispatch('user/loadUserCollections')
- },
- socketConnected(isConnected) {
- // if (isConnected) {
- // console.log('Connected - Load from server')
- // this.loadAudiobooks()
- // if (this.$route.name === 'bookshelf-collections') this.loadCollections()
- // } else {
- // console.log('Disconnected - Reset to local storage')
- // this.$store.commit('audiobooks/reset')
- // this.$store.dispatch('audiobooks/useDownloaded')
- // }
- }
- },
- mounted() {
- this.$server.on('connected', this.socketConnected)
- },
- beforeDestroy() {
- this.$server.off('connected', this.socketConnected)
}
}
diff --git a/pages/bookshelf/collections.vue b/pages/bookshelf/collections.vue
index f2aab925..1f180bc8 100644
--- a/pages/bookshelf/collections.vue
+++ b/pages/bookshelf/collections.vue
@@ -1,52 +1,14 @@
-
\ No newline at end of file
diff --git a/pages/bookshelf/index.vue b/pages/bookshelf/index.vue
index 3301a8f7..27ff631c 100644
--- a/pages/bookshelf/index.vue
+++ b/pages/bookshelf/index.vue
@@ -36,7 +36,13 @@ export default {
},
computed: {
books() {
- return this.$store.getters['downloads/getAudiobooks']
+ return this.$store.getters['downloads/getDownloads'].map((dl) => {
+ var download = { ...dl }
+ var ab = { ...download.audiobook }
+ delete download.audiobook
+ ab.download = download
+ return ab
+ })
},
isSocketConnected() {
return this.$store.state.socketConnected
@@ -141,18 +147,108 @@ export default {
} else {
this.shelves = this.downloadOnlyShelves
}
+ },
+ downloadsLoaded() {
+ if (!this.isSocketConnected) {
+ this.shelves = this.downloadOnlyShelves
+ }
+ },
+ audiobookAdded(audiobook) {
+ console.log('Audiobook added', audiobook)
+ // TODO: Check if audiobook would be on this shelf
+ if (!this.search) {
+ this.fetchCategories()
+ }
+ },
+ audiobookUpdated(audiobook) {
+ console.log('Audiobook updated', audiobook)
+ this.shelves.forEach((shelf) => {
+ if (shelf.type === 'books') {
+ shelf.entities = shelf.entities.map((ent) => {
+ if (ent.id === audiobook.id) {
+ return audiobook
+ }
+ return ent
+ })
+ } else if (shelf.type === 'series') {
+ shelf.entities.forEach((ent) => {
+ ent.books = ent.books.map((book) => {
+ if (book.id === audiobook.id) return audiobook
+ return book
+ })
+ })
+ }
+ })
+ },
+ removeBookFromShelf(audiobook) {
+ this.shelves.forEach((shelf) => {
+ if (shelf.type === 'books') {
+ shelf.entities = shelf.entities.filter((ent) => {
+ return ent.id !== audiobook.id
+ })
+ } else if (shelf.type === 'series') {
+ shelf.entities.forEach((ent) => {
+ ent.books = ent.books.filter((book) => {
+ return book.id !== audiobook.id
+ })
+ })
+ }
+ })
+ },
+ audiobookRemoved(audiobook) {
+ this.removeBookFromShelf(audiobook)
+ },
+ audiobooksAdded(audiobooks) {
+ console.log('audiobooks added', audiobooks)
+ // TODO: Check if audiobook would be on this shelf
+ this.fetchCategories()
+ },
+ audiobooksUpdated(audiobooks) {
+ audiobooks.forEach((ab) => {
+ this.audiobookUpdated(ab)
+ })
+ },
+ initListeners() {
+ this.$server.on('initialized', this.socketInit)
+ this.$eventBus.$on('library-changed', this.libraryChanged)
+ this.$eventBus.$on('downloads-loaded', this.downloadsLoaded)
+
+ if (this.$server.socket) {
+ this.$server.socket.on('audiobook_updated', this.audiobookUpdated)
+ this.$server.socket.on('audiobook_added', this.audiobookAdded)
+ this.$server.socket.on('audiobook_removed', this.audiobookRemoved)
+ this.$server.socket.on('audiobooks_updated', this.audiobooksUpdated)
+ this.$server.socket.on('audiobooks_added', this.audiobooksAdded)
+ } else {
+ console.error('Error socket not initialized')
+ }
+ },
+ removeListeners() {
+ this.$server.off('initialized', this.socketInit)
+ this.$eventBus.$off('library-changed', this.libraryChanged)
+ this.$eventBus.$off('downloads-loaded', this.downloadsLoaded)
+
+ if (this.$server.socket) {
+ this.$server.socket.off('audiobook_updated', this.audiobookUpdated)
+ this.$server.socket.off('audiobook_added', this.audiobookAdded)
+ this.$server.socket.off('audiobook_removed', this.audiobookRemoved)
+ this.$server.socket.off('audiobooks_updated', this.audiobooksUpdated)
+ this.$server.socket.off('audiobooks_added', this.audiobooksAdded)
+ } else {
+ console.error('Error socket not initialized')
+ }
}
},
mounted() {
- this.$server.on('initialized', this.socketInit)
- this.$eventBus.$on('library-changed', this.libraryChanged)
+ this.initListeners()
if (this.$server.initialized) {
this.fetchCategories()
+ } else {
+ this.shelves = this.downloadOnlyShelves
}
},
beforeDestroy() {
- this.$server.off('initialized', this.socketInit)
- this.$eventBus.$off('library-changed', this.libraryChanged)
+ this.removeListeners()
}
}
\ No newline at end of file
diff --git a/pages/bookshelf/series/index.vue b/pages/bookshelf/series/index.vue
index 0123badb..bf9e9ab3 100644
--- a/pages/bookshelf/series/index.vue
+++ b/pages/bookshelf/series/index.vue
@@ -1,11 +1,5 @@
-