2021-11-06 02:24:02 +01:00
|
|
|
<template>
|
2022-03-14 01:34:31 +01:00
|
|
|
<div id="page-wrapper" class="bg-bg page overflow-hidden" :class="streamLibraryItem ? 'streaming' : ''">
|
2021-11-06 02:24:02 +01:00
|
|
|
<div class="w-full h-full overflow-y-auto px-2 py-6 md:p-8">
|
|
|
|
<div class="flex flex-col sm:flex-row max-w-6xl mx-auto">
|
2021-11-07 02:31:46 +01:00
|
|
|
<div class="w-full flex justify-center md:block sm:w-32 md:w-52" style="min-width: 240px">
|
2021-11-06 02:24:02 +01:00
|
|
|
<div class="relative" style="height: fit-content">
|
2021-12-03 02:02:38 +01:00
|
|
|
<covers-collection-cover :book-items="bookItems" :width="240" :height="120 * bookCoverAspectRatio" :book-cover-aspect-ratio="bookCoverAspectRatio" />
|
2021-11-06 02:24:02 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="flex-grow px-2 py-6 md:py-0 md:px-10">
|
2022-08-05 01:06:39 +02:00
|
|
|
<div class="flex items-end flex-row flex-wrap md:flex-nowrap">
|
|
|
|
<h1 class="text-2xl md:text-3xl font-sans w-full md:w-fit mb-4 md:mb-0">
|
2021-11-07 02:31:46 +01:00
|
|
|
{{ collectionName }}
|
|
|
|
</h1>
|
|
|
|
<div class="flex-grow" />
|
|
|
|
|
2021-11-08 01:11:29 +01:00
|
|
|
<ui-btn v-if="showPlayButton" :disabled="streaming" color="success" :padding-x="4" small class="flex items-center h-9 mr-2" @click="clickPlay">
|
|
|
|
<span v-show="!streaming" class="material-icons -ml-2 pr-1 text-white">play_arrow</span>
|
2022-11-09 00:10:08 +01:00
|
|
|
{{ streaming ? $strings.ButtonPlaying : $strings.ButtonPlay }}
|
2021-11-08 01:11:29 +01:00
|
|
|
</ui-btn>
|
|
|
|
|
2022-08-31 22:46:10 +02:00
|
|
|
<ui-icon-btn v-if="userCanUpdate" icon="edit" class="mx-0.5" @click="editClick" />
|
2021-11-07 02:31:46 +01:00
|
|
|
|
2022-08-31 22:46:10 +02:00
|
|
|
<ui-icon-btn v-if="userCanDelete" icon="delete" class="mx-0.5" @click="removeClick" />
|
2021-11-07 02:31:46 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="my-8 max-w-2xl">
|
|
|
|
<p class="text-base text-gray-100">{{ description }}</p>
|
2021-11-06 02:24:02 +01:00
|
|
|
</div>
|
2021-11-07 02:31:46 +01:00
|
|
|
|
2021-11-07 22:28:06 +01:00
|
|
|
<tables-collection-books-table :books="bookItems" :collection-id="collection.id" />
|
2021-11-06 02:24:02 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-11-07 02:31:46 +01:00
|
|
|
<div v-show="processingRemove" class="absolute top-0 left-0 w-full h-full z-10 bg-black bg-opacity-40 flex items-center justify-center">
|
|
|
|
<ui-loading-indicator />
|
|
|
|
</div>
|
2021-11-06 02:24:02 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
async asyncData({ store, params, app, redirect, route }) {
|
|
|
|
if (!store.state.user.user) {
|
|
|
|
return redirect(`/login?redirect=${route.path}`)
|
|
|
|
}
|
2021-11-22 03:00:40 +01:00
|
|
|
var collection = await app.$axios.$get(`/api/collections/${params.id}`).catch((error) => {
|
2021-11-06 02:24:02 +01:00
|
|
|
console.error('Failed', error)
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
if (!collection) {
|
|
|
|
return redirect('/')
|
|
|
|
}
|
2022-04-14 19:57:34 +02:00
|
|
|
|
2021-11-06 02:24:02 +01:00
|
|
|
store.commit('user/addUpdateCollection', collection)
|
|
|
|
return {
|
2021-11-07 22:28:06 +01:00
|
|
|
collectionId: collection.id
|
2021-11-06 02:24:02 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
2021-11-07 02:31:46 +01:00
|
|
|
return {
|
2021-11-07 22:28:06 +01:00
|
|
|
processingRemove: false,
|
|
|
|
collectionCopy: {}
|
2021-11-07 02:31:46 +01:00
|
|
|
}
|
2021-11-06 02:24:02 +01:00
|
|
|
},
|
|
|
|
computed: {
|
2021-12-03 02:02:38 +01:00
|
|
|
bookCoverAspectRatio() {
|
2022-08-13 20:56:37 +02:00
|
|
|
return this.$store.getters['libraries/getBookCoverAspectRatio']
|
2021-12-03 02:02:38 +01:00
|
|
|
},
|
2022-03-14 01:34:31 +01:00
|
|
|
streamLibraryItem() {
|
|
|
|
return this.$store.state.streamLibraryItem
|
2021-11-06 02:24:02 +01:00
|
|
|
},
|
|
|
|
bookItems() {
|
|
|
|
return this.collection.books || []
|
|
|
|
},
|
|
|
|
collectionName() {
|
|
|
|
return this.collection.name || ''
|
2021-11-07 02:31:46 +01:00
|
|
|
},
|
|
|
|
description() {
|
|
|
|
return this.collection.description || ''
|
2021-11-07 22:28:06 +01:00
|
|
|
},
|
|
|
|
collection() {
|
|
|
|
return this.$store.getters['user/getCollection'](this.collectionId)
|
2021-11-08 01:11:29 +01:00
|
|
|
},
|
|
|
|
playableBooks() {
|
|
|
|
return this.bookItems.filter((book) => {
|
2022-03-26 17:59:34 +01:00
|
|
|
return !book.isMissing && !book.isInvalid && book.media.tracks.length
|
2021-11-08 01:11:29 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
streaming() {
|
2022-03-13 02:59:35 +01:00
|
|
|
return !!this.playableBooks.find((b) => b.id === this.$store.getters['getLibraryItemIdStreaming'])
|
2021-11-08 01:11:29 +01:00
|
|
|
},
|
|
|
|
showPlayButton() {
|
|
|
|
return this.playableBooks.length
|
2022-08-31 22:46:10 +02:00
|
|
|
},
|
|
|
|
userCanUpdate() {
|
|
|
|
return this.$store.getters['user/getUserCanUpdate']
|
|
|
|
},
|
|
|
|
userCanDelete() {
|
|
|
|
return this.$store.getters['user/getUserCanDelete']
|
2021-11-07 02:31:46 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
editClick() {
|
|
|
|
this.$store.commit('globals/setEditCollection', this.collection)
|
|
|
|
},
|
|
|
|
removeClick() {
|
|
|
|
if (confirm(`Are you sure you want to remove collection "${this.collectionName}"?`)) {
|
|
|
|
this.processingRemove = true
|
|
|
|
var collectionName = this.collectionName
|
|
|
|
this.$axios
|
2021-11-22 03:00:40 +01:00
|
|
|
.$delete(`/api/collections/${this.collection.id}`)
|
2021-11-07 02:31:46 +01:00
|
|
|
.then(() => {
|
|
|
|
this.processingRemove = false
|
|
|
|
this.$toast.success(`Collection "${collectionName}" Removed`)
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to remove collection', error)
|
|
|
|
this.processingRemove = false
|
|
|
|
this.$toast.error(`Failed to remove collection`)
|
|
|
|
})
|
|
|
|
}
|
2021-11-07 22:28:06 +01:00
|
|
|
},
|
2021-11-08 01:11:29 +01:00
|
|
|
clickPlay() {
|
2022-03-20 22:16:39 +01:00
|
|
|
var nextBookNotRead = this.playableBooks.find((pb) => {
|
2022-03-26 17:59:34 +01:00
|
|
|
var prog = this.$store.getters['user/getUserMediaProgress'](pb.id)
|
2022-03-20 22:16:39 +01:00
|
|
|
return !prog || !prog.isFinished
|
|
|
|
})
|
2021-11-08 01:11:29 +01:00
|
|
|
if (nextBookNotRead) {
|
2022-03-26 23:41:26 +01:00
|
|
|
this.$eventBus.$emit('play-item', {
|
|
|
|
libraryItemId: nextBookNotRead.id
|
|
|
|
})
|
2021-11-08 01:11:29 +01:00
|
|
|
}
|
2021-11-06 02:24:02 +01:00
|
|
|
}
|
|
|
|
},
|
2021-11-08 01:11:29 +01:00
|
|
|
mounted() {},
|
2021-11-07 22:28:06 +01:00
|
|
|
beforeDestroy() {}
|
2021-11-06 02:24:02 +01:00
|
|
|
}
|
|
|
|
</script>
|