2021-11-14 19:59:34 -06:00
|
|
|
<template>
|
2021-12-31 16:57:53 -06:00
|
|
|
<div class="w-full h-full min-h-full relative">
|
2022-04-03 17:07:26 -05:00
|
|
|
<div v-if="!loading" class="w-full">
|
|
|
|
<template v-for="(shelf, index) in shelves">
|
|
|
|
<bookshelf-shelf :key="shelf.id" :label="shelf.label" :entities="shelf.entities" :type="shelf.type" :style="{ zIndex: shelves.length - index }" />
|
|
|
|
</template>
|
|
|
|
</div>
|
2021-12-04 19:56:29 -06:00
|
|
|
|
2022-04-23 00:56:46 -04:00
|
|
|
<div v-if="!shelves.length && !loading" class="absolute top-0 left-0 w-full h-full flex items-center justify-center">
|
2021-12-04 19:56:29 -06:00
|
|
|
<div>
|
|
|
|
<p class="mb-4 text-center text-xl">
|
2021-12-31 16:57:53 -06:00
|
|
|
Bookshelf empty
|
2022-04-03 14:24:17 -05:00
|
|
|
<span v-show="user">
|
2021-12-31 16:57:53 -06:00
|
|
|
for library
|
|
|
|
<strong>{{ currentLibraryName }}</strong>
|
|
|
|
</span>
|
2021-12-04 19:56:29 -06:00
|
|
|
</p>
|
2022-04-03 14:24:17 -05:00
|
|
|
<div class="w-full" v-if="!user">
|
2021-12-04 19:56:29 -06:00
|
|
|
<div class="flex justify-center items-center mb-3">
|
|
|
|
<span class="material-icons text-error text-lg">cloud_off</span>
|
|
|
|
<p class="pl-2 text-error text-sm">Audiobookshelf server not connected.</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="flex justify-center">
|
2022-04-03 14:24:17 -05:00
|
|
|
<ui-btn v-if="!user" small @click="$router.push('/connect')" class="w-32">Connect</ui-btn>
|
2021-12-04 19:56:29 -06:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-23 00:56:46 -04:00
|
|
|
<div v-if="loading" class="absolute top-0 left-0 w-full h-full flex items-center justify-center">
|
2022-04-23 14:38:29 -05:00
|
|
|
<ui-loading-indicator text="Loading Library..." />
|
2022-04-23 00:56:46 -04:00
|
|
|
</div>
|
2021-11-14 19:59:34 -06:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2021-12-04 19:56:29 -06:00
|
|
|
shelves: [],
|
2022-04-07 18:46:58 -05:00
|
|
|
loading: false,
|
|
|
|
localLibraryItems: []
|
2021-11-14 19:59:34 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2022-04-03 14:24:17 -05:00
|
|
|
user() {
|
|
|
|
return this.$store.state.user.user
|
|
|
|
},
|
2021-12-04 19:56:29 -06:00
|
|
|
isSocketConnected() {
|
|
|
|
return this.$store.state.socketConnected
|
|
|
|
},
|
|
|
|
currentLibraryName() {
|
|
|
|
return this.$store.getters['libraries/getCurrentLibraryName']
|
2021-11-14 19:59:34 -06:00
|
|
|
},
|
2021-12-04 19:56:29 -06:00
|
|
|
currentLibraryId() {
|
|
|
|
return this.$store.state.libraries.currentLibraryId
|
2021-11-14 19:59:34 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-04-03 17:07:26 -05:00
|
|
|
async getLocalMediaItemCategories() {
|
|
|
|
var localMedia = await this.$db.getLocalLibraryItems()
|
2022-04-07 18:46:58 -05:00
|
|
|
console.log('Got local library items', localMedia ? localMedia.length : 'N/A')
|
2022-04-03 17:07:26 -05:00
|
|
|
if (!localMedia || !localMedia.length) return []
|
2022-04-07 18:46:58 -05:00
|
|
|
|
2022-04-03 17:07:26 -05:00
|
|
|
var categories = []
|
|
|
|
var books = []
|
|
|
|
var podcasts = []
|
|
|
|
localMedia.forEach((item) => {
|
|
|
|
if (item.mediaType == 'book') {
|
|
|
|
books.push(item)
|
|
|
|
} else if (item.mediaType == 'podcast') {
|
|
|
|
podcasts.push(item)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if (books.length) {
|
|
|
|
categories.push({
|
|
|
|
id: 'local-books',
|
|
|
|
label: 'Local Books',
|
|
|
|
type: 'book',
|
2022-04-17 17:54:13 -05:00
|
|
|
entities: books.slice(0, 10)
|
2021-12-04 19:56:29 -06:00
|
|
|
})
|
2022-04-03 17:07:26 -05:00
|
|
|
}
|
|
|
|
if (podcasts.length) {
|
|
|
|
categories.push({
|
|
|
|
id: 'local-podcasts',
|
|
|
|
label: 'Local Podcasts',
|
|
|
|
type: 'podcast',
|
2022-04-17 17:54:13 -05:00
|
|
|
entities: podcasts.slice(0, 10)
|
2021-12-04 19:56:29 -06:00
|
|
|
})
|
2022-04-03 17:07:26 -05:00
|
|
|
}
|
2022-04-07 18:46:58 -05:00
|
|
|
|
2022-04-03 17:07:26 -05:00
|
|
|
return categories
|
|
|
|
},
|
2022-04-07 19:59:23 -05:00
|
|
|
async fetchCategories() {
|
2022-04-04 19:08:27 -05:00
|
|
|
if (this.loading) {
|
|
|
|
console.log('Already loading categories')
|
|
|
|
return
|
|
|
|
}
|
2022-04-03 17:07:26 -05:00
|
|
|
this.loading = true
|
|
|
|
this.shelves = []
|
|
|
|
|
2022-04-07 18:46:58 -05:00
|
|
|
this.localLibraryItems = await this.$db.getLocalLibraryItems()
|
|
|
|
|
2022-04-03 17:07:26 -05:00
|
|
|
var localCategories = await this.getLocalMediaItemCategories()
|
|
|
|
this.shelves = this.shelves.concat(localCategories)
|
|
|
|
|
2022-04-05 19:44:14 -05:00
|
|
|
if (this.user && this.currentLibraryId) {
|
2022-04-07 18:46:58 -05:00
|
|
|
var 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) => {
|
|
|
|
console.log('[breadcrumb] Personalized category from server', cat.type)
|
|
|
|
if (cat.type == 'book' || cat.type == 'podcast') {
|
|
|
|
// Map localLibraryItem to entities
|
|
|
|
cat.entities = cat.entities.map((entity) => {
|
|
|
|
var localLibraryItem = this.localLibraryItems.find((lli) => {
|
|
|
|
return lli.libraryItemId == entity.id
|
|
|
|
})
|
|
|
|
if (localLibraryItem) {
|
|
|
|
entity.localLibraryItem = localLibraryItem
|
|
|
|
}
|
|
|
|
return entity
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return cat
|
|
|
|
})
|
2022-04-09 20:29:59 -05:00
|
|
|
// 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'))
|
2022-04-03 17:07:26 -05:00
|
|
|
}
|
|
|
|
this.loading = false
|
2021-12-04 19:56:29 -06:00
|
|
|
},
|
2022-06-05 16:32:28 -05:00
|
|
|
async libraryChanged() {
|
2022-04-07 18:46:58 -05:00
|
|
|
if (this.currentLibraryId) {
|
2022-04-07 19:59:23 -05:00
|
|
|
await this.fetchCategories()
|
2021-12-05 18:31:47 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
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
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
initListeners() {
|
|
|
|
this.$eventBus.$on('library-changed', this.libraryChanged)
|
2022-04-03 17:07:26 -05:00
|
|
|
// this.$eventBus.$on('downloads-loaded', this.downloadsLoaded)
|
2021-12-05 18:31:47 -06:00
|
|
|
},
|
|
|
|
removeListeners() {
|
|
|
|
this.$eventBus.$off('library-changed', this.libraryChanged)
|
2022-04-03 17:07:26 -05:00
|
|
|
// this.$eventBus.$off('downloads-loaded', this.downloadsLoaded)
|
2021-12-04 19:56:29 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
2021-12-05 18:31:47 -06:00
|
|
|
this.initListeners()
|
2022-04-07 19:59:23 -05:00
|
|
|
this.fetchCategories()
|
2022-04-03 14:24:17 -05:00
|
|
|
// if (this.$server.initialized && this.currentLibraryId) {
|
|
|
|
// this.fetchCategories()
|
|
|
|
// } else {
|
|
|
|
// this.shelves = this.downloadOnlyShelves
|
|
|
|
// }
|
2021-11-14 19:59:34 -06:00
|
|
|
},
|
2021-12-04 19:56:29 -06:00
|
|
|
beforeDestroy() {
|
2021-12-05 18:31:47 -06:00
|
|
|
this.removeListeners()
|
2021-12-04 19:56:29 -06:00
|
|
|
}
|
2021-11-14 19:59:34 -06:00
|
|
|
}
|
|
|
|
</script>
|