2021-09-28 13:44:40 +02:00
|
|
|
<template>
|
2024-06-03 08:04:03 +02:00
|
|
|
<div id="bookshelf" ref="wrapper" class="w-full max-w-full h-full overflow-y-scroll relative" :style="{ fontSize: sizeMultiplier + 'rem' }">
|
2021-09-28 13:44:40 +02:00
|
|
|
<!-- Cover size widget -->
|
2024-06-23 18:15:39 +02:00
|
|
|
<widgets-cover-size-widget class="fixed right-4 z-50" :style="{ bottom: streamLibraryItem ? '181px' : '16px' }" />
|
2021-09-28 13:44:40 +02:00
|
|
|
|
2022-05-04 02:16:16 +02:00
|
|
|
<div v-if="loaded && !shelves.length && !search" class="w-full flex flex-col items-center justify-center py-12">
|
2024-05-13 23:31:30 +02:00
|
|
|
<p class="text-center text-2xl mb-4 py-4">{{ $getString('MessageXLibraryIsEmpty', [libraryName]) }}</p>
|
2022-05-04 02:16:16 +02:00
|
|
|
<div v-if="userIsAdminOrUp" class="flex">
|
2024-05-13 23:31:30 +02:00
|
|
|
<ui-btn to="/config" color="primary" class="w-52 mr-2">{{ $strings.ButtonConfigureScanner }}</ui-btn>
|
|
|
|
<ui-btn color="success" class="w-52" :loading="isScanningLibrary || tempIsScanning" @click="scan">{{ $strings.ButtonScanLibrary }}</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">
|
2024-05-30 23:28:46 +02:00
|
|
|
<p class="text-center text-xl py-4">{{ $strings.MessageBookshelfNoResultsForQuery }}</p>
|
2022-03-13 18:39:12 +01:00
|
|
|
</div>
|
2022-05-10 01:23:23 +02:00
|
|
|
<!-- Alternate plain view -->
|
2024-06-23 18:15:39 +02:00
|
|
|
<div v-else-if="isAlternativeBookshelfView" class="w-full mb-24e">
|
2024-06-03 08:04:03 +02:00
|
|
|
<template v-for="(shelf, index) in supportedShelves">
|
2024-06-23 18:15:39 +02:00
|
|
|
<widgets-item-slider :shelf-id="shelf.id" :key="index + '.'" :items="shelf.entities" :continue-listening-shelf="shelf.id === 'continue-listening' || shelf.id === 'continue-reading'" :type="shelf.type" class="bookshelf-row pl-8e my-6e" @selectEntity="(payload) => selectEntity(payload, index)">
|
2024-06-03 08:04:03 +02:00
|
|
|
<p class="font-semibold text-gray-100">{{ $strings[shelf.labelStringKey] }}</p>
|
2022-05-10 01:23:23 +02:00
|
|
|
</widgets-item-slider>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
<!-- Regular bookshelf view -->
|
|
|
|
<div v-else class="w-full">
|
2024-06-24 23:44:29 +02:00
|
|
|
<template v-for="(shelf, index) in supportedShelves">
|
2023-05-27 16:00:54 +02:00
|
|
|
<app-book-shelf-row :key="index" :index="index" :shelf="shelf" :size-multiplier="sizeMultiplier" :book-cover-width="bookCoverWidth" :book-cover-aspect-ratio="coverAspectRatio" :continue-listening-shelf="shelf.id === 'continue-listening' || shelf.id === 'continue-reading'" @selectEntity="(payload) => selectEntity(payload, index)" />
|
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,
|
2022-10-16 00:17:40 +02:00
|
|
|
shelves: [],
|
2024-05-13 23:31:30 +02:00
|
|
|
lastItemIndexSelected: -1,
|
|
|
|
tempIsScanning: false
|
2021-09-28 13:44:40 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2024-06-03 08:04:03 +02:00
|
|
|
supportedShelves() {
|
2024-06-03 20:57:40 +02:00
|
|
|
return this.shelves.filter((shelf) => ['book', 'podcast', 'episode', 'series', 'authors', 'narrators'].includes(shelf.type))
|
2024-06-03 08:04:03 +02:00
|
|
|
},
|
2022-05-04 02:16:16 +02:00
|
|
|
userIsAdminOrUp() {
|
|
|
|
return this.$store.getters['user/getIsAdminOrUp']
|
2021-12-02 02:07:03 +01:00
|
|
|
},
|
2021-12-01 03:02:40 +01:00
|
|
|
currentLibraryId() {
|
|
|
|
return this.$store.state.libraries.currentLibraryId
|
2021-09-28 13:44:40 +02:00
|
|
|
},
|
2023-08-05 21:01:16 +02:00
|
|
|
currentLibraryMediaType() {
|
|
|
|
return this.$store.getters['libraries/getCurrentLibraryMediaType']
|
|
|
|
},
|
2022-03-27 22:37:04 +02:00
|
|
|
libraryName() {
|
|
|
|
return this.$store.getters['libraries/getCurrentLibraryName']
|
|
|
|
},
|
2022-05-10 01:23:23 +02:00
|
|
|
isAlternativeBookshelfView() {
|
2022-10-22 16:13:20 +02:00
|
|
|
return this.$store.getters['getHomeBookshelfView'] === this.$constants.BookshelfView.DETAIL
|
2022-05-10 01:23:23 +02:00
|
|
|
},
|
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() {
|
2022-08-13 20:56:37 +02:00
|
|
|
return this.$store.getters['libraries/getBookCoverAspectRatio']
|
2021-12-02 22:49:03 +01:00
|
|
|
},
|
|
|
|
isCoverSquareAspectRatio() {
|
2022-08-13 20:56:37 +02:00
|
|
|
return this.coverAspectRatio == 1
|
2021-09-28 13:44:40 +02:00
|
|
|
},
|
|
|
|
sizeMultiplier() {
|
2024-06-03 08:04:03 +02:00
|
|
|
return this.$store.getters['user/getSizeMultiplier']
|
2022-10-16 00:17:40 +02:00
|
|
|
},
|
2022-12-01 00:09:00 +01:00
|
|
|
selectedMediaItems() {
|
|
|
|
return this.$store.state.globals.selectedMediaItems || []
|
2023-12-23 17:50:04 +01:00
|
|
|
},
|
|
|
|
streamLibraryItem() {
|
|
|
|
return this.$store.state.streamLibraryItem
|
2024-05-13 23:31:30 +02:00
|
|
|
},
|
|
|
|
isScanningLibrary() {
|
|
|
|
return !!this.$store.getters['tasks/getRunningLibraryScanTask'](this.currentLibraryId)
|
2021-09-28 13:44:40 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-10-16 00:17:40 +02:00
|
|
|
selectEntity({ entity, shiftKey }, shelfIndex) {
|
|
|
|
const shelf = this.shelves[shelfIndex]
|
|
|
|
const entityShelfIndex = shelf.entities.findIndex((ent) => ent.id === entity.id)
|
|
|
|
const indexOf = shelf.shelfStartIndex + entityShelfIndex
|
|
|
|
|
|
|
|
const lastLastItemIndexSelected = this.lastItemIndexSelected
|
2022-12-01 00:09:00 +01:00
|
|
|
if (!this.selectedMediaItems.some((i) => i.id === entity.id)) {
|
2022-10-16 00:17:40 +02:00
|
|
|
this.lastItemIndexSelected = indexOf
|
|
|
|
} else {
|
|
|
|
this.lastItemIndexSelected = -1
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shiftKey && lastLastItemIndexSelected >= 0) {
|
2022-12-01 00:09:00 +01:00
|
|
|
let loopStart = indexOf
|
|
|
|
let loopEnd = lastLastItemIndexSelected
|
2022-10-16 00:17:40 +02:00
|
|
|
if (indexOf > lastLastItemIndexSelected) {
|
|
|
|
loopStart = lastLastItemIndexSelected
|
|
|
|
loopEnd = indexOf
|
|
|
|
}
|
|
|
|
|
|
|
|
const flattenedEntitiesArray = []
|
|
|
|
this.shelves.map((s) => flattenedEntitiesArray.push(...s.entities))
|
|
|
|
|
2022-12-01 00:09:00 +01:00
|
|
|
let isSelecting = false
|
2022-10-16 00:17:40 +02:00
|
|
|
// If any items in this range is not selected then select all otherwise unselect all
|
|
|
|
for (let i = loopStart; i <= loopEnd; i++) {
|
|
|
|
const thisEntity = flattenedEntitiesArray[i]
|
|
|
|
if (thisEntity) {
|
2022-12-01 00:09:00 +01:00
|
|
|
if (!this.selectedMediaItems.some((i) => i.id === thisEntity.id)) {
|
2022-10-16 00:17:40 +02:00
|
|
|
isSelecting = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isSelecting) this.lastItemIndexSelected = indexOf
|
|
|
|
|
|
|
|
for (let i = loopStart; i <= loopEnd; i++) {
|
|
|
|
const thisEntity = flattenedEntitiesArray[i]
|
|
|
|
if (thisEntity) {
|
2022-12-01 00:09:00 +01:00
|
|
|
const mediaItem = {
|
|
|
|
id: thisEntity.id,
|
|
|
|
mediaType: thisEntity.mediaType,
|
2023-01-04 01:00:01 +01:00
|
|
|
hasTracks: thisEntity.mediaType === 'podcast' || thisEntity.media.audioFile || thisEntity.media.numTracks || (thisEntity.media.tracks && thisEntity.media.tracks.length)
|
2022-12-01 00:09:00 +01:00
|
|
|
}
|
|
|
|
this.$store.commit('globals/setMediaItemSelected', { item: mediaItem, selected: isSelecting })
|
2022-10-16 00:17:40 +02:00
|
|
|
} else {
|
|
|
|
console.error('Invalid entity index', i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2022-12-01 00:09:00 +01:00
|
|
|
const mediaItem = {
|
|
|
|
id: entity.id,
|
|
|
|
mediaType: entity.mediaType,
|
2023-01-04 01:00:01 +01:00
|
|
|
hasTracks: entity.mediaType === 'podcast' || entity.media.audioFile || entity.media.numTracks || (entity.media.tracks && entity.media.tracks.length)
|
2022-12-01 00:09:00 +01:00
|
|
|
}
|
|
|
|
this.$store.commit('globals/toggleMediaItemSelected', mediaItem)
|
2022-10-16 00:17:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$eventBus.$emit('item-selected', entity)
|
|
|
|
})
|
|
|
|
},
|
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() {
|
2024-07-14 07:25:56 +02:00
|
|
|
// Sets the limit for the number of items to be displayed based on the viewport width.
|
|
|
|
const viewportWidth = window.innerWidth
|
|
|
|
let limit
|
2024-07-15 17:15:06 +02:00
|
|
|
if (viewportWidth >= 3240) {
|
2024-07-14 07:25:56 +02:00
|
|
|
limit = 15
|
|
|
|
} else if (viewportWidth >= 2880 && viewportWidth < 3240) {
|
|
|
|
limit = 12
|
|
|
|
}
|
|
|
|
|
|
|
|
const limitQuery = limit ? `&limit=${limit}` : ''
|
|
|
|
|
2022-12-31 21:31:38 +01:00
|
|
|
const categories = await this.$axios
|
2024-07-14 07:25:56 +02:00
|
|
|
.$get(`/api/libraries/${this.currentLibraryId}/personalized?include=rssfeed,numEpisodesIncomplete,share${limitQuery}`)
|
2021-12-02 02:07:03 +01:00
|
|
|
.then((data) => {
|
|
|
|
return data
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to fetch categories', error)
|
|
|
|
return []
|
|
|
|
})
|
2022-10-16 00:17:40 +02:00
|
|
|
|
|
|
|
let totalEntityCount = 0
|
|
|
|
for (const shelf of categories) {
|
|
|
|
shelf.shelfStartIndex = totalEntityCount
|
|
|
|
totalEntityCount += shelf.entities.length
|
|
|
|
}
|
2021-12-02 02:07:03 +01:00
|
|
|
this.shelves = categories
|
|
|
|
},
|
2021-12-01 03:02:40 +01:00
|
|
|
async setShelvesFromSearch() {
|
2023-04-25 01:25:30 +02:00
|
|
|
const shelves = []
|
|
|
|
if (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-11-09 00:10:08 +01:00
|
|
|
labelStringKey: 'LabelBooks',
|
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
|
|
|
|
2023-04-25 01:25:30 +02:00
|
|
|
if (this.results.podcasts?.length) {
|
2022-04-12 23:54:52 +02:00
|
|
|
shelves.push({
|
|
|
|
id: 'podcasts',
|
|
|
|
label: 'Podcasts',
|
2022-11-09 00:10:08 +01:00
|
|
|
labelStringKey: 'LabelPodcasts',
|
2022-04-12 23:54:52 +02:00
|
|
|
type: 'podcast',
|
|
|
|
entities: this.results.podcasts.map((res) => res.libraryItem)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-04-25 01:25:30 +02:00
|
|
|
if (this.results.series?.length) {
|
2021-12-01 03:02:40 +01:00
|
|
|
shelves.push({
|
|
|
|
id: 'series',
|
|
|
|
label: 'Series',
|
2022-11-09 00:10:08 +01:00
|
|
|
labelStringKey: 'LabelSeries',
|
2021-12-01 03:02:40 +01:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2023-04-25 01:25:30 +02:00
|
|
|
if (this.results.tags?.length) {
|
2021-12-01 03:02:40 +01:00
|
|
|
shelves.push({
|
|
|
|
id: 'tags',
|
|
|
|
label: 'Tags',
|
2022-11-09 00:10:08 +01:00
|
|
|
labelStringKey: 'LabelTags',
|
2021-12-01 03:02:40 +01:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2023-04-25 01:25:30 +02:00
|
|
|
if (this.results.authors?.length) {
|
2021-12-03 02:02:38 +01:00
|
|
|
shelves.push({
|
|
|
|
id: 'authors',
|
|
|
|
label: 'Authors',
|
2022-11-09 00:10:08 +01:00
|
|
|
labelStringKey: 'LabelAuthors',
|
2021-12-03 02:02:38 +01:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2023-04-25 01:25:30 +02:00
|
|
|
if (this.results.narrators?.length) {
|
|
|
|
shelves.push({
|
|
|
|
id: 'narrators',
|
|
|
|
label: 'Narrators',
|
|
|
|
labelStringKey: 'LabelNarrators',
|
|
|
|
type: 'narrators',
|
|
|
|
entities: this.results.narrators.map((n) => {
|
|
|
|
return {
|
|
|
|
...n,
|
|
|
|
type: 'narrator'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
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
|
|
|
scan() {
|
2024-05-13 23:31:30 +02:00
|
|
|
this.tempIsScanning = true
|
2022-05-18 23:33:24 +02:00
|
|
|
this.$store
|
|
|
|
.dispatch('libraries/requestLibraryScan', { libraryId: this.$store.state.libraries.currentLibraryId })
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to start scan', error)
|
2024-05-13 23:31:30 +02:00
|
|
|
this.$toast.error(this.$strings.ToastLibraryScanFailedToStart)
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.tempIsScanning = false
|
2022-05-18 23:33:24 +02:00
|
|
|
})
|
2021-12-02 02:07:03 +01:00
|
|
|
},
|
2022-09-29 00:12:27 +02:00
|
|
|
userUpdated(user) {
|
|
|
|
if (user.seriesHideFromContinueListening && user.seriesHideFromContinueListening.length) {
|
|
|
|
this.removeAllSeriesFromContinueSeries(user.seriesHideFromContinueListening)
|
|
|
|
}
|
2022-09-29 00:45:39 +02:00
|
|
|
if (user.mediaProgress.length) {
|
2022-09-29 00:57:27 +02:00
|
|
|
const mediaProgressToHide = user.mediaProgress.filter((mp) => mp.hideFromContinueListening)
|
2023-05-27 16:00:54 +02:00
|
|
|
this.removeItemsFromContinueListeningReading(mediaProgressToHide, 'continue-listening')
|
|
|
|
this.removeItemsFromContinueListeningReading(mediaProgressToHide, 'continue-reading')
|
2022-09-29 00:45:39 +02:00
|
|
|
}
|
2022-09-29 00:12:27 +02: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)
|
2023-05-27 16:13:44 +02:00
|
|
|
|
2024-09-18 22:30:24 +02:00
|
|
|
// First items added to library
|
|
|
|
const isThisLibrary = libraryItems.some((li) => li.libraryId === this.currentLibraryId)
|
|
|
|
if (!this.shelves.length && !this.search && isThisLibrary) {
|
|
|
|
this.fetchCategories()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-11-24 22:36:42 +01:00
|
|
|
const recentlyAddedShelf = this.shelves.find((shelf) => shelf.id === 'recently-added')
|
|
|
|
if (!recentlyAddedShelf) return
|
|
|
|
|
|
|
|
// Add new library item to the recently added shelf
|
|
|
|
for (const libraryItem of libraryItems) {
|
|
|
|
if (libraryItem.libraryId === this.currentLibraryId && !recentlyAddedShelf.entities.some((ent) => ent.id === libraryItem.id)) {
|
|
|
|
// Add to front of array
|
|
|
|
recentlyAddedShelf.entities.unshift(libraryItem)
|
|
|
|
}
|
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
|
|
|
})
|
|
|
|
},
|
2023-05-27 16:13:44 +02:00
|
|
|
episodeAdded(episodeWithLibraryItem) {
|
|
|
|
const isThisLibrary = episodeWithLibraryItem.libraryItem?.libraryId === this.currentLibraryId
|
|
|
|
if (!this.search && isThisLibrary) {
|
|
|
|
this.fetchCategories()
|
|
|
|
}
|
|
|
|
},
|
2022-09-29 00:12:27 +02:00
|
|
|
removeAllSeriesFromContinueSeries(seriesIds) {
|
|
|
|
this.shelves.forEach((shelf) => {
|
|
|
|
if (shelf.type == 'book' && shelf.id == 'continue-series') {
|
|
|
|
// Filter out series books from continue series shelf
|
|
|
|
shelf.entities = shelf.entities.filter((ent) => {
|
|
|
|
if (ent.media.metadata.series && seriesIds.includes(ent.media.metadata.series.id)) return false
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2022-09-28 00:48:45 +02:00
|
|
|
},
|
2023-05-27 16:00:54 +02:00
|
|
|
removeItemsFromContinueListeningReading(mediaProgressItems, categoryId) {
|
|
|
|
const continueListeningShelf = this.shelves.find((s) => s.id === categoryId)
|
2022-09-29 00:57:27 +02:00
|
|
|
if (continueListeningShelf) {
|
|
|
|
if (continueListeningShelf.type === 'book') {
|
|
|
|
continueListeningShelf.entities = continueListeningShelf.entities.filter((ent) => {
|
|
|
|
if (mediaProgressItems.some((mp) => mp.libraryItemId === ent.id)) return false
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
} else if (continueListeningShelf.type === 'episode') {
|
|
|
|
continueListeningShelf.entities = continueListeningShelf.entities.filter((ent) => {
|
|
|
|
if (!ent.recentEpisode) return true // Should always have this here
|
|
|
|
if (mediaProgressItems.some((mp) => mp.libraryItemId === ent.id && mp.episodeId === ent.recentEpisode.id)) return false
|
2022-09-29 00:45:39 +02:00
|
|
|
return true
|
|
|
|
})
|
|
|
|
}
|
2022-09-29 00:57:27 +02:00
|
|
|
}
|
2022-09-29 00:45:39 +02: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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2024-07-08 00:19:44 +02:00
|
|
|
shareOpen(mediaItemShare) {
|
|
|
|
this.shelves.forEach((shelf) => {
|
|
|
|
if (shelf.type == 'book') {
|
|
|
|
shelf.entities = shelf.entities.map((ent) => {
|
|
|
|
if (ent.media.id === mediaItemShare.mediaItemId) {
|
|
|
|
return {
|
|
|
|
...ent,
|
|
|
|
mediaItemShare
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ent
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
shareClosed(mediaItemShare) {
|
|
|
|
this.shelves.forEach((shelf) => {
|
|
|
|
if (shelf.type == 'book') {
|
|
|
|
shelf.entities = shelf.entities.map((ent) => {
|
|
|
|
if (ent.media.id === mediaItemShare.mediaItemId) {
|
|
|
|
return {
|
|
|
|
...ent,
|
|
|
|
mediaItemShare: null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ent
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2021-12-02 02:07:03 +01:00
|
|
|
initListeners() {
|
|
|
|
if (this.$root.socket) {
|
2022-09-29 00:12:27 +02:00
|
|
|
this.$root.socket.on('user_updated', this.userUpdated)
|
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)
|
2023-05-27 16:13:44 +02:00
|
|
|
this.$root.socket.on('episode_added', this.episodeAdded)
|
2024-07-08 00:19:44 +02:00
|
|
|
this.$root.socket.on('share_open', this.shareOpen)
|
|
|
|
this.$root.socket.on('share_closed', this.shareClosed)
|
2021-12-02 02:07:03 +01:00
|
|
|
} else {
|
|
|
|
console.error('Error socket not initialized')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeListeners() {
|
|
|
|
if (this.$root.socket) {
|
2022-09-29 00:12:27 +02:00
|
|
|
this.$root.socket.off('user_updated', this.userUpdated)
|
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)
|
2023-05-27 16:13:44 +02:00
|
|
|
this.$root.socket.off('episode_added', this.episodeAdded)
|
2024-07-08 00:19:44 +02:00
|
|
|
this.$root.socket.off('share_open', this.shareOpen)
|
|
|
|
this.$root.socket.off('share_closed', this.shareClosed)
|
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>
|