2021-11-07 02:31:46 +01:00
|
|
|
<template>
|
2022-08-05 01:06:39 +02:00
|
|
|
<div class="w-full px-1 md:px-2 py-2 overflow-hidden relative" @mouseover="mouseover" @mouseleave="mouseleave" :class="isHovering ? 'bg-white bg-opacity-5' : ''">
|
2023-05-25 00:37:51 +02:00
|
|
|
<div v-if="book" class="flex h-18 md:h-[5.5rem]">
|
2022-08-05 01:06:39 +02:00
|
|
|
<div class="w-10 min-w-10 md:w-16 md:max-w-16 h-full">
|
2021-11-07 22:28:06 +01:00
|
|
|
<div class="flex h-full items-center justify-center">
|
2024-07-08 18:36:37 +02:00
|
|
|
<span class="material-symbols drag-handle text-lg md:text-xl">menu</span>
|
2021-11-07 22:28:06 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-05-25 00:37:51 +02:00
|
|
|
<div class="h-full flex items-center" :style="{ width: coverWidth + 'px', minWidth: coverWidth + 'px', maxWidth: coverWidth + 'px' }">
|
|
|
|
<div class="relative" :style="{ height: coverHeight + 'px', minHeight: coverHeight + 'px', maxHeight: coverHeight + 'px' }">
|
|
|
|
<covers-book-cover :library-item="book" :width="coverWidth" :book-cover-aspect-ratio="bookCoverAspectRatio" />
|
|
|
|
<div class="absolute top-0 left-0 flex items-center justify-center bg-black bg-opacity-50 h-full w-full z-10" v-show="isHovering && showPlayBtn">
|
|
|
|
<div class="w-8 h-8 bg-white bg-opacity-20 rounded-full flex items-center justify-center hover:bg-opacity-40 cursor-pointer" @click="playClick">
|
2024-07-09 00:00:16 +02:00
|
|
|
<span class="material-symbols fill text-2xl">play_arrow</span>
|
2023-05-25 00:37:51 +02:00
|
|
|
</div>
|
2021-11-08 01:11:29 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-10-28 00:46:51 +02:00
|
|
|
<div class="flex-grow overflow-hidden max-w-48 md:max-w-md h-full flex items-center px-2 md:px-3">
|
|
|
|
<div>
|
|
|
|
<div class="truncate max-w-48 md:max-w-md">
|
|
|
|
<nuxt-link :to="`/item/${book.id}`" class="truncate hover:underline text-sm md:text-base">{{ bookTitle }}</nuxt-link>
|
|
|
|
</div>
|
2023-05-25 00:37:51 +02:00
|
|
|
<div class="truncate max-w-48 md:max-w-md text-xs md:text-sm text-gray-300">
|
|
|
|
<nuxt-link v-for="_series in seriesList" :key="_series.id" :to="`/library/${book.libraryId}/series/${_series.id}`" class="hover:underline font-sans text-gray-300"> {{ _series.text }}</nuxt-link>
|
|
|
|
</div>
|
2022-10-28 00:46:51 +02:00
|
|
|
<div class="truncate max-w-48 md:max-w-md text-xs md:text-sm text-gray-300">
|
|
|
|
<template v-for="(author, index) in bookAuthors">
|
2023-10-19 00:10:53 +02:00
|
|
|
<nuxt-link :key="author.id" :to="`/author/${author.id}`" class="truncate hover:underline">{{ author.name }}</nuxt-link
|
2022-10-28 00:46:51 +02:00
|
|
|
><span :key="author.id + '-comma'" v-if="index < bookAuthors.length - 1">, </span>
|
|
|
|
</template>
|
|
|
|
</div>
|
2023-11-06 23:18:35 +01:00
|
|
|
<p v-if="media.duration" class="text-xs md:text-sm text-gray-400">{{ bookDuration }}</p>
|
2021-11-07 02:31:46 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-08-31 22:46:10 +02:00
|
|
|
<div class="w-40 absolute top-0 -right-24 h-full transform transition-transform" :class="!isHovering ? 'translate-x-0' : translateDistance">
|
2021-11-07 22:28:06 +01:00
|
|
|
<div class="flex h-full items-center">
|
2022-11-09 00:10:08 +01:00
|
|
|
<ui-tooltip :text="userIsFinished ? $strings.MessageMarkAsNotFinished : $strings.MessageMarkAsFinished" direction="top">
|
2022-03-17 19:33:22 +01:00
|
|
|
<ui-read-icon-btn :disabled="isProcessingReadUpdate" :is-read="userIsFinished" borderless class="mx-1 mt-0.5" @click="toggleFinished" />
|
2021-11-07 22:28:06 +01:00
|
|
|
</ui-tooltip>
|
2022-08-31 22:46:10 +02:00
|
|
|
<div v-if="userCanUpdate" class="mx-1" :class="isHovering ? '' : 'ml-6'">
|
2021-11-07 22:28:06 +01:00
|
|
|
<ui-icon-btn icon="edit" borderless @click="clickEdit" />
|
|
|
|
</div>
|
2022-08-31 22:46:10 +02:00
|
|
|
<div v-if="userCanDelete" class="mx-1">
|
2021-11-07 22:28:06 +01:00
|
|
|
<ui-icon-btn icon="close" borderless @click="removeClick" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-11-07 02:31:46 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
2021-11-07 22:28:06 +01:00
|
|
|
collectionId: String,
|
2021-11-07 02:31:46 +01:00
|
|
|
book: {
|
|
|
|
type: Object,
|
|
|
|
default: () => {}
|
2021-11-08 01:11:29 +01:00
|
|
|
},
|
2021-12-03 02:02:38 +01:00
|
|
|
isDragging: Boolean,
|
|
|
|
bookCoverAspectRatio: Number
|
2021-11-07 02:31:46 +01:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2021-11-07 22:28:06 +01:00
|
|
|
isProcessingReadUpdate: false,
|
|
|
|
processingRemove: false,
|
2021-11-07 02:31:46 +01:00
|
|
|
isHovering: false
|
|
|
|
}
|
|
|
|
},
|
2021-11-07 22:28:06 +01:00
|
|
|
watch: {
|
2021-11-08 01:11:29 +01:00
|
|
|
isDragging: {
|
|
|
|
handler(newVal) {
|
|
|
|
if (newVal) {
|
|
|
|
this.isHovering = false
|
|
|
|
}
|
|
|
|
}
|
2021-11-07 22:28:06 +01:00
|
|
|
}
|
|
|
|
},
|
2021-11-07 02:31:46 +01:00
|
|
|
computed: {
|
2022-08-31 22:46:10 +02:00
|
|
|
translateDistance() {
|
|
|
|
if (!this.userCanUpdate && !this.userCanDelete) return 'translate-x-0'
|
|
|
|
else if (!this.userCanUpdate || !this.userCanDelete) return '-translate-x-12'
|
|
|
|
return '-translate-x-24'
|
|
|
|
},
|
2022-03-13 01:50:31 +01:00
|
|
|
media() {
|
|
|
|
return this.book.media || {}
|
|
|
|
},
|
|
|
|
mediaMetadata() {
|
|
|
|
return this.media.metadata || {}
|
2021-11-07 02:31:46 +01:00
|
|
|
},
|
2022-03-26 17:59:34 +01:00
|
|
|
tracks() {
|
|
|
|
return this.media.tracks || []
|
|
|
|
},
|
2021-11-07 02:31:46 +01:00
|
|
|
bookTitle() {
|
2022-03-13 01:50:31 +01:00
|
|
|
return this.mediaMetadata.title || ''
|
2021-11-07 02:31:46 +01:00
|
|
|
},
|
2022-10-28 00:46:51 +02:00
|
|
|
bookAuthors() {
|
|
|
|
return this.mediaMetadata.authors || []
|
2021-11-07 02:31:46 +01:00
|
|
|
},
|
|
|
|
bookDuration() {
|
2022-10-28 00:46:51 +02:00
|
|
|
return this.$elapsedPretty(this.media.duration)
|
2021-11-07 22:28:06 +01:00
|
|
|
},
|
2023-05-25 00:37:51 +02:00
|
|
|
series() {
|
|
|
|
return this.mediaMetadata.series || []
|
|
|
|
},
|
|
|
|
seriesList() {
|
|
|
|
return this.series.map((se) => {
|
|
|
|
let text = se.name
|
|
|
|
if (se.sequence) text += ` #${se.sequence}`
|
|
|
|
return {
|
|
|
|
...se,
|
|
|
|
text
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2021-11-08 01:11:29 +01:00
|
|
|
isMissing() {
|
|
|
|
return this.book.isMissing
|
|
|
|
},
|
2021-12-02 02:07:03 +01:00
|
|
|
isInvalid() {
|
|
|
|
return this.book.isInvalid
|
2021-11-08 01:11:29 +01:00
|
|
|
},
|
|
|
|
isStreaming() {
|
2022-03-13 02:59:35 +01:00
|
|
|
return this.$store.getters['getLibraryItemIdStreaming'] === this.book.id
|
2021-11-08 01:11:29 +01:00
|
|
|
},
|
|
|
|
showPlayBtn() {
|
2022-03-26 17:59:34 +01:00
|
|
|
return !this.isMissing && !this.isInvalid && !this.isStreaming && this.tracks.length
|
2021-11-08 01:11:29 +01:00
|
|
|
},
|
2022-03-17 19:33:22 +01:00
|
|
|
itemProgress() {
|
2022-03-26 17:59:34 +01:00
|
|
|
return this.$store.getters['user/getUserMediaProgress'](this.book.id)
|
2021-11-07 22:28:06 +01:00
|
|
|
},
|
2022-03-17 19:33:22 +01:00
|
|
|
userIsFinished() {
|
|
|
|
return this.itemProgress ? !!this.itemProgress.isFinished : false
|
2021-12-03 02:02:38 +01:00
|
|
|
},
|
2022-08-05 01:06:39 +02:00
|
|
|
coverSize() {
|
2022-10-28 00:46:51 +02:00
|
|
|
return this.$store.state.globals.isMobile ? 30 : 50
|
2022-08-05 01:06:39 +02:00
|
|
|
},
|
2023-05-25 00:37:51 +02:00
|
|
|
coverHeight() {
|
|
|
|
return this.coverSize * 1.6
|
|
|
|
},
|
2021-12-03 02:02:38 +01:00
|
|
|
coverWidth() {
|
2022-08-05 01:06:39 +02:00
|
|
|
if (this.bookCoverAspectRatio === 1) return this.coverSize * 1.6
|
|
|
|
return this.coverSize
|
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: {
|
|
|
|
mouseover() {
|
2021-11-08 01:11:29 +01:00
|
|
|
if (this.isDragging) return
|
2021-11-07 02:31:46 +01:00
|
|
|
this.isHovering = true
|
|
|
|
},
|
|
|
|
mouseleave() {
|
|
|
|
this.isHovering = false
|
2021-11-07 22:28:06 +01:00
|
|
|
},
|
2021-11-08 01:11:29 +01:00
|
|
|
playClick() {
|
2022-11-12 23:48:35 +01:00
|
|
|
const queueItems = [
|
|
|
|
{
|
|
|
|
libraryItemId: this.book.id,
|
|
|
|
libraryId: this.book.libraryId,
|
|
|
|
episodeId: null,
|
|
|
|
title: this.bookTitle,
|
|
|
|
subtitle: this.bookAuthors.map((au) => au.name).join(', '),
|
|
|
|
caption: '',
|
|
|
|
duration: this.media.duration || null,
|
|
|
|
coverPath: this.media.coverPath || null
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2022-03-26 23:41:26 +01:00
|
|
|
this.$eventBus.$emit('play-item', {
|
2022-11-12 23:48:35 +01:00
|
|
|
libraryItemId: this.book.id,
|
|
|
|
queueItems
|
2022-03-26 23:41:26 +01:00
|
|
|
})
|
2021-11-08 01:11:29 +01:00
|
|
|
},
|
2021-11-07 22:28:06 +01:00
|
|
|
clickEdit() {
|
|
|
|
this.$emit('edit', this.book)
|
|
|
|
},
|
2022-03-17 19:33:22 +01:00
|
|
|
toggleFinished() {
|
2021-11-07 22:28:06 +01:00
|
|
|
var updatePayload = {
|
2022-03-17 19:33:22 +01:00
|
|
|
isFinished: !this.userIsFinished
|
2021-11-07 22:28:06 +01:00
|
|
|
}
|
|
|
|
this.isProcessingReadUpdate = true
|
|
|
|
this.$axios
|
2022-03-17 19:33:22 +01:00
|
|
|
.$patch(`/api/me/progress/${this.book.id}`, updatePayload)
|
2021-11-07 22:28:06 +01:00
|
|
|
.then(() => {
|
|
|
|
this.isProcessingReadUpdate = false
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed', error)
|
|
|
|
this.isProcessingReadUpdate = false
|
2022-11-09 00:10:08 +01:00
|
|
|
this.$toast.error(updatePayload.isFinished ? this.$strings.ToastItemMarkedAsFinishedFailed : this.$strings.ToastItemMarkedAsNotFinishedFailed)
|
2021-11-07 22:28:06 +01:00
|
|
|
})
|
|
|
|
},
|
|
|
|
removeClick() {
|
|
|
|
this.processingRemove = true
|
|
|
|
|
|
|
|
this.$axios
|
2021-11-22 03:00:40 +01:00
|
|
|
.$delete(`/api/collections/${this.collectionId}/book/${this.book.id}`)
|
2021-11-07 22:28:06 +01:00
|
|
|
.then((updatedCollection) => {
|
|
|
|
console.log(`Book removed from collection`, updatedCollection)
|
2022-11-09 00:10:08 +01:00
|
|
|
this.$toast.success(this.$strings.ToastRemoveItemFromCollectionSuccess)
|
2021-11-07 22:28:06 +01:00
|
|
|
this.processingRemove = false
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to remove book from collection', error)
|
2022-11-09 00:10:08 +01:00
|
|
|
this.$toast.error(this.$strings.ToastRemoveItemFromCollectionFailed)
|
2021-11-07 22:28:06 +01:00
|
|
|
this.processingRemove = false
|
|
|
|
})
|
2021-11-07 02:31:46 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
|
|
|
</script>
|