2021-09-28 13:44:40 +02:00
|
|
|
<template>
|
|
|
|
<div id="bookshelf" ref="wrapper" class="w-full h-full overflow-y-scroll relative">
|
|
|
|
<!-- Cover size widget -->
|
2021-12-02 02:07:03 +01:00
|
|
|
<widgets-cover-size-widget class="fixed bottom-4 right-4 z-30" />
|
2021-11-28 03:11:35 +01:00
|
|
|
<!-- Experimental Bookshelf Texture -->
|
|
|
|
<div v-show="showExperimentalFeatures" class="fixed bottom-4 right-28 z-40">
|
|
|
|
<div class="rounded-full py-1 bg-primary hover:bg-bg cursor-pointer px-2 border border-black-100 text-center flex items-center box-shadow-md" @mousedown.prevent @mouseup.prevent @click="showBookshelfTextureModal"><p class="text-sm py-0.5">Texture</p></div>
|
|
|
|
</div>
|
2021-09-28 13:44:40 +02:00
|
|
|
|
2022-03-13 18:39:12 +01:00
|
|
|
<div v-if="loaded && !shelves.length && isRootUser && !search" class="w-full flex flex-col items-center justify-center py-12">
|
2022-03-27 22:37:04 +02:00
|
|
|
<p class="text-center text-2xl font-book mb-4 py-4">{{ libraryName }} Library is empty!</p>
|
2021-09-28 13:44:40 +02:00
|
|
|
<div class="flex">
|
2021-12-02 02:07:03 +01:00
|
|
|
<ui-btn to="/config" color="primary" class="w-52 mr-2">Configure Scanner</ui-btn>
|
2022-03-14 01:34:31 +01:00
|
|
|
<ui-btn color="success" class="w-52" @click="scan">Scan Library</ui-btn>
|
2021-09-28 13:44:40 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-03-13 18:39:12 +01:00
|
|
|
<div v-else-if="loaded && !shelves.length && search" class="w-full h-40 flex items-center justify-center">
|
|
|
|
<p class="text-center text-xl font-book py-4">No results for query</p>
|
|
|
|
</div>
|
2021-11-04 23:35:59 +01:00
|
|
|
<div v-else class="w-full flex flex-col items-center">
|
2021-09-28 13:44:40 +02:00
|
|
|
<template v-for="(shelf, index) in shelves">
|
2021-12-02 22:49:03 +01:00
|
|
|
<app-book-shelf-row :key="index" :index="index" :shelf="shelf" :size-multiplier="sizeMultiplier" :book-cover-width="bookCoverWidth" :book-cover-aspect-ratio="bookCoverAspectRatio" />
|
2021-09-28 13:44:40 +02:00
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
2021-12-01 03:02:40 +01:00
|
|
|
props: {
|
|
|
|
search: Boolean,
|
|
|
|
results: {
|
|
|
|
type: Object,
|
|
|
|
default: () => {}
|
|
|
|
}
|
|
|
|
},
|
2021-09-28 13:44:40 +02:00
|
|
|
data() {
|
|
|
|
return {
|
2021-12-01 03:02:40 +01:00
|
|
|
loaded: false,
|
2021-09-28 13:44:40 +02:00
|
|
|
keywordFilterTimeout: null,
|
|
|
|
scannerParseSubtitle: false,
|
2021-09-29 00:36:41 +02:00
|
|
|
wrapperClientWidth: 0,
|
2021-12-01 03:02:40 +01:00
|
|
|
shelves: []
|
2021-09-28 13:44:40 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2021-12-02 02:07:03 +01:00
|
|
|
isRootUser() {
|
|
|
|
return this.$store.getters['user/getIsRoot']
|
|
|
|
},
|
2021-11-28 03:11:35 +01:00
|
|
|
showExperimentalFeatures() {
|
|
|
|
return this.$store.state.showExperimentalFeatures
|
|
|
|
},
|
2021-12-01 03:02:40 +01:00
|
|
|
currentLibraryId() {
|
|
|
|
return this.$store.state.libraries.currentLibraryId
|
2021-09-28 13:44:40 +02:00
|
|
|
},
|
2022-03-27 22:37:04 +02:00
|
|
|
libraryName() {
|
|
|
|
return this.$store.getters['libraries/getCurrentLibraryName']
|
|
|
|
},
|
2021-09-28 13:44:40 +02:00
|
|
|
bookCoverWidth() {
|
2021-12-02 22:49:03 +01:00
|
|
|
var coverSize = this.$store.getters['user/getUserSetting']('bookshelfCoverSize')
|
|
|
|
if (this.isCoverSquareAspectRatio) return coverSize * 1.6
|
|
|
|
return coverSize
|
|
|
|
},
|
|
|
|
coverAspectRatio() {
|
|
|
|
return this.$store.getters['getServerSetting']('coverAspectRatio')
|
|
|
|
},
|
|
|
|
isCoverSquareAspectRatio() {
|
|
|
|
return this.coverAspectRatio === this.$constants.BookCoverAspectRatio.SQUARE
|
|
|
|
},
|
|
|
|
bookCoverAspectRatio() {
|
|
|
|
return this.isCoverSquareAspectRatio ? 1 : 1.6
|
2021-09-28 13:44:40 +02:00
|
|
|
},
|
|
|
|
sizeMultiplier() {
|
2021-12-03 02:02:38 +01:00
|
|
|
var baseSize = this.isCoverSquareAspectRatio ? 192 : 120
|
|
|
|
return this.bookCoverWidth / baseSize
|
2021-09-28 13:44:40 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-11-28 03:11:35 +01:00
|
|
|
showBookshelfTextureModal() {
|
|
|
|
this.$store.commit('globals/setShowBookshelfTextureModal', true)
|
|
|
|
},
|
2021-09-28 13:44:40 +02:00
|
|
|
async init() {
|
|
|
|
this.wrapperClientWidth = this.$refs.wrapper ? this.$refs.wrapper.clientWidth : 0
|
|
|
|
|
2021-12-01 03:02:40 +01:00
|
|
|
if (this.search) {
|
|
|
|
this.setShelvesFromSearch()
|
|
|
|
} else {
|
2021-12-02 02:07:03 +01:00
|
|
|
await this.fetchCategories()
|
2021-12-01 03:02:40 +01:00
|
|
|
}
|
|
|
|
this.loaded = true
|
|
|
|
},
|
2021-12-02 02:07:03 +01:00
|
|
|
async fetchCategories() {
|
|
|
|
var categories = await this.$axios
|
2022-04-24 23:56:30 +02:00
|
|
|
.$get(`/api/libraries/${this.currentLibraryId}/personalized`)
|
2021-12-02 02:07:03 +01:00
|
|
|
.then((data) => {
|
|
|
|
return data
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to fetch categories', error)
|
|
|
|
return []
|
|
|
|
})
|
|
|
|
this.shelves = categories
|
|
|
|
},
|
2021-12-01 03:02:40 +01:00
|
|
|
async setShelvesFromSearch() {
|
|
|
|
var shelves = []
|
2022-04-12 23:54:52 +02:00
|
|
|
if (this.results.books && this.results.books.length) {
|
2021-12-01 03:02:40 +01:00
|
|
|
shelves.push({
|
2022-03-13 18:39:12 +01:00
|
|
|
id: 'books',
|
2021-12-01 03:02:40 +01:00
|
|
|
label: 'Books',
|
2022-03-17 18:25:12 +01:00
|
|
|
type: 'book',
|
2022-03-13 18:39:12 +01:00
|
|
|
entities: this.results.books.map((res) => res.libraryItem)
|
2021-12-01 03:02:40 +01:00
|
|
|
})
|
|
|
|
}
|
2021-12-02 02:07:03 +01:00
|
|
|
|
2022-04-12 23:54:52 +02:00
|
|
|
if (this.results.podcasts && this.results.podcasts.length) {
|
|
|
|
shelves.push({
|
|
|
|
id: 'podcasts',
|
|
|
|
label: 'Podcasts',
|
|
|
|
type: 'podcast',
|
|
|
|
entities: this.results.podcasts.map((res) => res.libraryItem)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.results.series && this.results.series.length) {
|
2021-12-01 03:02:40 +01:00
|
|
|
shelves.push({
|
|
|
|
id: 'series',
|
|
|
|
label: 'Series',
|
|
|
|
type: 'series',
|
|
|
|
entities: this.results.series.map((seriesObj) => {
|
|
|
|
return {
|
2022-04-30 00:12:02 +02:00
|
|
|
...seriesObj.series,
|
2022-03-13 18:39:12 +01:00
|
|
|
books: seriesObj.books,
|
2021-12-01 03:02:40 +01:00
|
|
|
type: 'series'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2022-04-12 23:54:52 +02:00
|
|
|
if (this.results.tags && this.results.tags.length) {
|
2021-12-01 03:02:40 +01:00
|
|
|
shelves.push({
|
|
|
|
id: 'tags',
|
|
|
|
label: 'Tags',
|
|
|
|
type: 'tags',
|
|
|
|
entities: this.results.tags.map((tagObj) => {
|
|
|
|
return {
|
2022-03-13 18:39:12 +01:00
|
|
|
name: tagObj.name,
|
|
|
|
books: tagObj.books || [],
|
2021-12-01 03:02:40 +01:00
|
|
|
type: 'tags'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2022-04-12 23:54:52 +02:00
|
|
|
if (this.results.authors && this.results.authors.length) {
|
2021-12-03 02:02:38 +01:00
|
|
|
shelves.push({
|
|
|
|
id: 'authors',
|
|
|
|
label: 'Authors',
|
|
|
|
type: 'authors',
|
|
|
|
entities: this.results.authors.map((a) => {
|
|
|
|
return {
|
2022-03-13 18:39:12 +01:00
|
|
|
...a,
|
2021-12-03 02:02:38 +01:00
|
|
|
type: 'author'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2021-12-01 03:02:40 +01:00
|
|
|
this.shelves = shelves
|
2021-09-28 13:44:40 +02:00
|
|
|
},
|
2021-12-02 02:07:03 +01:00
|
|
|
settingsUpdated(settings) {},
|
|
|
|
scan() {
|
2022-03-18 17:51:55 +01:00
|
|
|
this.$store.dispatch('libraries/requestLibraryScan', { libraryId: this.$store.state.libraries.currentLibraryId })
|
2021-12-02 02:07:03 +01:00
|
|
|
},
|
2022-03-13 01:50:31 +01:00
|
|
|
libraryItemAdded(libraryItem) {
|
|
|
|
console.log('libraryItem added', libraryItem)
|
|
|
|
// TODO: Check if libraryItem would be on this shelf
|
2021-12-02 02:07:03 +01:00
|
|
|
if (!this.search) {
|
|
|
|
this.fetchCategories()
|
|
|
|
}
|
|
|
|
},
|
2022-03-13 01:50:31 +01:00
|
|
|
libraryItemUpdated(libraryItem) {
|
|
|
|
console.log('libraryItem updated', libraryItem)
|
2021-12-02 02:07:03 +01:00
|
|
|
this.shelves.forEach((shelf) => {
|
2022-03-26 23:41:26 +01:00
|
|
|
if (shelf.type == 'book' || shelf.type == 'podcast') {
|
2021-12-02 02:07:03 +01:00
|
|
|
shelf.entities = shelf.entities.map((ent) => {
|
2022-03-13 01:50:31 +01:00
|
|
|
if (ent.id === libraryItem.id) {
|
|
|
|
return libraryItem
|
2021-12-02 02:07:03 +01:00
|
|
|
}
|
|
|
|
return ent
|
|
|
|
})
|
|
|
|
} else if (shelf.type === 'series') {
|
|
|
|
shelf.entities.forEach((ent) => {
|
|
|
|
ent.books = ent.books.map((book) => {
|
2022-03-13 01:50:31 +01:00
|
|
|
if (book.id === libraryItem.id) return libraryItem
|
2021-12-02 02:07:03 +01:00
|
|
|
return book
|
|
|
|
})
|
|
|
|
})
|
2021-09-28 13:44:40 +02:00
|
|
|
}
|
2021-12-02 02:07:03 +01:00
|
|
|
})
|
|
|
|
},
|
2022-03-13 01:50:31 +01:00
|
|
|
removeBookFromShelf(libraryItem) {
|
2021-12-02 02:07:03 +01:00
|
|
|
this.shelves.forEach((shelf) => {
|
2022-03-26 23:41:26 +01:00
|
|
|
if (shelf.type == 'book' || shelf.type == 'podcast') {
|
2021-12-02 02:07:03 +01:00
|
|
|
shelf.entities = shelf.entities.filter((ent) => {
|
2022-03-13 01:50:31 +01:00
|
|
|
return ent.id !== libraryItem.id
|
2021-12-02 02:07:03 +01:00
|
|
|
})
|
|
|
|
} else if (shelf.type === 'series') {
|
|
|
|
shelf.entities.forEach((ent) => {
|
|
|
|
ent.books = ent.books.filter((book) => {
|
2022-03-13 01:50:31 +01:00
|
|
|
return book.id !== libraryItem.id
|
2021-12-02 02:07:03 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2022-03-13 01:50:31 +01:00
|
|
|
libraryItemRemoved(libraryItem) {
|
|
|
|
this.removeBookFromShelf(libraryItem)
|
2021-12-02 02:07:03 +01:00
|
|
|
},
|
2022-03-13 01:50:31 +01:00
|
|
|
libraryItemsAdded(libraryItems) {
|
|
|
|
console.log('libraryItems added', libraryItems)
|
2021-12-02 02:07:03 +01:00
|
|
|
// TODO: Check if audiobook would be on this shelf
|
|
|
|
if (!this.search) {
|
|
|
|
this.fetchCategories()
|
2021-09-28 13:44:40 +02:00
|
|
|
}
|
|
|
|
},
|
2022-03-13 01:50:31 +01:00
|
|
|
libraryItemsUpdated(items) {
|
|
|
|
items.forEach((li) => {
|
|
|
|
this.libraryItemUpdated(li)
|
2021-12-02 02:07:03 +01:00
|
|
|
})
|
|
|
|
},
|
2022-03-27 23:16:08 +02:00
|
|
|
authorUpdated(author) {
|
|
|
|
this.shelves.forEach((shelf) => {
|
|
|
|
if (shelf.type == 'authors') {
|
|
|
|
shelf.entities = shelf.entities.map((ent) => {
|
|
|
|
if (ent.id === author.id) {
|
|
|
|
return {
|
|
|
|
...ent,
|
|
|
|
...author
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ent
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
authorRemoved(author) {
|
|
|
|
this.shelves.forEach((shelf) => {
|
|
|
|
if (shelf.type == 'authors') {
|
|
|
|
shelf.entities = shelf.entities.filter((ent) => ent.id != author.id)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2021-12-02 02:07:03 +01:00
|
|
|
initListeners() {
|
|
|
|
this.$store.commit('user/addSettingsListener', { id: 'bookshelf', meth: this.settingsUpdated })
|
|
|
|
|
|
|
|
if (this.$root.socket) {
|
2022-03-27 23:16:08 +02:00
|
|
|
this.$root.socket.on('author_updated', this.authorUpdated)
|
|
|
|
this.$root.socket.on('author_removed', this.authorRemoved)
|
2022-03-13 01:50:31 +01:00
|
|
|
this.$root.socket.on('item_updated', this.libraryItemUpdated)
|
|
|
|
this.$root.socket.on('item_added', this.libraryItemAdded)
|
|
|
|
this.$root.socket.on('item_removed', this.libraryItemRemoved)
|
|
|
|
this.$root.socket.on('items_updated', this.libraryItemsUpdated)
|
|
|
|
this.$root.socket.on('items_added', this.libraryItemsAdded)
|
2021-12-02 02:07:03 +01:00
|
|
|
} else {
|
|
|
|
console.error('Error socket not initialized')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeListeners() {
|
|
|
|
this.$store.commit('user/removeSettingsListener', 'bookshelf')
|
|
|
|
|
|
|
|
if (this.$root.socket) {
|
2022-03-27 23:16:08 +02:00
|
|
|
this.$root.socket.off('author_updated', this.authorUpdated)
|
|
|
|
this.$root.socket.off('author_removed', this.authorRemoved)
|
2022-03-13 01:50:31 +01:00
|
|
|
this.$root.socket.off('item_updated', this.libraryItemUpdated)
|
|
|
|
this.$root.socket.off('item_added', this.libraryItemAdded)
|
|
|
|
this.$root.socket.off('item_removed', this.libraryItemRemoved)
|
|
|
|
this.$root.socket.off('items_updated', this.libraryItemsUpdated)
|
|
|
|
this.$root.socket.off('items_added', this.libraryItemsAdded)
|
2021-12-02 02:07:03 +01:00
|
|
|
} else {
|
|
|
|
console.error('Error socket not initialized')
|
|
|
|
}
|
2021-09-28 13:44:40 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
2021-12-02 02:07:03 +01:00
|
|
|
this.initListeners()
|
2021-09-28 13:44:40 +02:00
|
|
|
this.init()
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
2021-12-02 02:07:03 +01:00
|
|
|
this.removeListeners()
|
2021-09-28 13:44:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|