2021-11-07 02:31:46 +01:00
|
|
|
<template>
|
2021-11-07 22:28:06 +01:00
|
|
|
<div class="w-full px-2 py-2 overflow-hidden relative" @mouseover="mouseover" @mouseleave="mouseleave" :class="isHovering ? 'bg-white bg-opacity-5' : ''">
|
2021-11-07 02:31:46 +01:00
|
|
|
<div v-if="book" class="flex h-20">
|
2021-11-07 22:28:06 +01:00
|
|
|
<div class="w-16 max-w-16 h-full">
|
|
|
|
<div class="flex h-full items-center justify-center">
|
|
|
|
<span class="material-icons drag-handle text-xl">menu</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-12-03 02:02:38 +01:00
|
|
|
<div class="h-full relative" :style="{ width: coverWidth + 'px' }">
|
2022-03-13 01:50:31 +01:00
|
|
|
<covers-book-cover :library-item="book" :width="coverWidth" :book-cover-aspect-ratio="bookCoverAspectRatio" />
|
2021-12-03 02:02:38 +01:00
|
|
|
<div class="absolute top-0 left-0 bg-black bg-opacity-50 flex items-center justify-center h-full w-full z-10" v-show="isHovering && showPlayBtn">
|
2021-11-08 01:11:29 +01:00
|
|
|
<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">
|
|
|
|
<span class="material-icons">play_arrow</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-11-07 02:31:46 +01:00
|
|
|
<div class="w-80 h-full px-2 flex items-center">
|
|
|
|
<div>
|
2022-03-13 01:50:31 +01:00
|
|
|
<nuxt-link :to="`/item/${book.id}`" class="truncate hover:underline">{{ bookTitle }}</nuxt-link>
|
|
|
|
<!-- <nuxt-link :to="`/library/${book.libraryId}/bookshelf?filter=authors.${$encode(bookAuthor)}`" class="truncate block text-gray-400 text-sm hover:underline">{{ bookAuthor }}</nuxt-link> -->
|
2021-11-07 02:31:46 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="flex-grow flex items-center">
|
2021-11-07 22:28:06 +01:00
|
|
|
<p class="font-mono text-sm">{{ bookDuration }}</p>
|
2021-11-07 02:31:46 +01:00
|
|
|
</div>
|
2021-11-07 22:28:06 +01:00
|
|
|
|
2021-11-07 02:31:46 +01:00
|
|
|
<!-- <div class="w-12 flex items-center justify-center">
|
|
|
|
<span class="material-icons text-lg text-white text-opacity-70 hover:text-opacity-100 cursor-pointer">radio_button_unchecked</span>
|
|
|
|
</div> -->
|
|
|
|
</div>
|
2021-11-07 22:28:06 +01:00
|
|
|
<!-- <div class="absolute top-0 left-0 z-40 bg-red-500 w-full h-full">
|
|
|
|
<div class="w-24 h-full absolute top-0 -right-24 transform transition-transform" :class="isHovering ? 'translate-x-0' : '-translate-x-24'">
|
|
|
|
<span class="material-icons">edit</span>
|
|
|
|
</div>
|
|
|
|
</div> -->
|
2021-11-08 01:11:29 +01:00
|
|
|
<div class="w-40 absolute top-0 -right-24 h-full transform transition-transform" :class="!isHovering ? 'translate-x-0' : '-translate-x-24'">
|
2021-11-07 22:28:06 +01:00
|
|
|
<div class="flex h-full items-center">
|
|
|
|
<ui-tooltip :text="isRead ? 'Mark as Not Read' : 'Mark as Read'" direction="top">
|
|
|
|
<ui-read-icon-btn :disabled="isProcessingReadUpdate" :is-read="isRead" borderless class="mx-1 mt-0.5" @click="toggleRead" />
|
|
|
|
</ui-tooltip>
|
2021-11-08 01:11:29 +01:00
|
|
|
<div class="mx-1" :class="isHovering ? '' : 'ml-6'">
|
2021-11-07 22:28:06 +01:00
|
|
|
<ui-icon-btn icon="edit" borderless @click="clickEdit" />
|
|
|
|
</div>
|
|
|
|
<div class="mx-1">
|
|
|
|
<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: {
|
|
|
|
userIsRead: {
|
|
|
|
immediate: true,
|
|
|
|
handler(newVal) {
|
|
|
|
this.isRead = newVal
|
|
|
|
}
|
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-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
|
|
|
},
|
|
|
|
bookTitle() {
|
2022-03-13 01:50:31 +01:00
|
|
|
return this.mediaMetadata.title || ''
|
2021-11-07 02:31:46 +01:00
|
|
|
},
|
|
|
|
bookAuthor() {
|
2022-03-13 01:50:31 +01:00
|
|
|
return (this.mediaMetadata.authors || []).map((au) => au.name).join(', ')
|
2021-11-07 02:31:46 +01:00
|
|
|
},
|
|
|
|
bookDuration() {
|
2022-03-13 01:50:31 +01:00
|
|
|
return this.$secondsToTimestamp(this.media.duration)
|
2021-11-07 22:28:06 +01:00
|
|
|
},
|
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
|
|
|
},
|
|
|
|
numTracks() {
|
2022-03-13 01:50:31 +01:00
|
|
|
return this.media.tracks.length
|
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() {
|
2021-12-02 02:07:03 +01:00
|
|
|
return !this.isMissing && !this.isInvalid && !this.isStreaming && this.numTracks
|
2021-11-08 01:11:29 +01:00
|
|
|
},
|
2021-11-07 22:28:06 +01:00
|
|
|
userAudiobooks() {
|
|
|
|
return this.$store.state.user.user ? this.$store.state.user.user.audiobooks || {} : {}
|
|
|
|
},
|
|
|
|
userAudiobook() {
|
|
|
|
return this.userAudiobooks[this.book.id] || null
|
|
|
|
},
|
|
|
|
userIsRead() {
|
|
|
|
return this.userAudiobook ? !!this.userAudiobook.isRead : false
|
2021-12-03 02:02:38 +01:00
|
|
|
},
|
|
|
|
coverWidth() {
|
|
|
|
if (this.bookCoverAspectRatio === 1) return 50 * 1.6
|
|
|
|
return 50
|
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-03-13 02:59:35 +01:00
|
|
|
this.$eventBus.$emit('play-item', this.book.id)
|
2021-11-08 01:11:29 +01:00
|
|
|
},
|
2021-11-07 22:28:06 +01:00
|
|
|
clickEdit() {
|
|
|
|
this.$emit('edit', this.book)
|
|
|
|
},
|
|
|
|
toggleRead() {
|
|
|
|
var updatePayload = {
|
|
|
|
isRead: !this.isRead
|
|
|
|
}
|
|
|
|
this.isProcessingReadUpdate = true
|
|
|
|
this.$axios
|
2021-11-22 03:00:40 +01:00
|
|
|
.$patch(`/api/me/audiobook/${this.book.id}`, updatePayload)
|
2021-11-07 22:28:06 +01:00
|
|
|
.then(() => {
|
|
|
|
this.isProcessingReadUpdate = false
|
2021-11-09 23:55:50 +01:00
|
|
|
this.$toast.success(`"${this.bookTitle}" Marked as ${updatePayload.isRead ? 'Read' : 'Not Read'}`)
|
2021-11-07 22:28:06 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed', error)
|
|
|
|
this.isProcessingReadUpdate = false
|
|
|
|
this.$toast.error(`Failed to mark as ${updatePayload.isRead ? 'Read' : 'Not Read'}`)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
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)
|
|
|
|
this.$toast.success('Book removed from collection')
|
|
|
|
this.processingRemove = false
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to remove book from collection', error)
|
|
|
|
this.$toast.error('Failed to remove book from collection')
|
|
|
|
this.processingRemove = false
|
|
|
|
})
|
2021-11-07 02:31:46 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
|
|
|
</script>
|