2021-08-18 00:01:11 +02:00
|
|
|
<template>
|
2021-08-21 16:15:44 +02:00
|
|
|
<div class="relative rounded-sm overflow-hidden" :style="{ height: width * 1.6 + 'px', width: width + 'px', maxWidth: width + 'px', minWidth: width + 'px' }">
|
2021-08-21 20:02:24 +02:00
|
|
|
<img ref="cover" :src="cover" @error="imageError" class="w-full h-full object-cover" />
|
2021-08-18 00:01:11 +02:00
|
|
|
|
2021-08-21 20:02:24 +02:00
|
|
|
<div v-if="imageFailed" class="absolute top-0 left-0 right-0 bottom-0 w-full h-full bg-red-100" :style="{ padding: placeholderCoverPadding + 'rem' }">
|
|
|
|
<div class="w-full h-full border-2 border-error flex flex-col items-center justify-center">
|
|
|
|
<img src="/LogoTransparent.png" class="mb-2" :style="{ height: 64 * sizeMultiplier + 'px' }" />
|
|
|
|
<p class="text-center font-book text-error" :style="{ fontSize: titleFontSize + 'rem' }">Invalid Cover</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-08-25 03:24:40 +02:00
|
|
|
|
2021-08-18 00:01:11 +02:00
|
|
|
<div v-if="!hasCover" class="absolute top-0 left-0 right-0 bottom-0 w-full h-full flex items-center justify-center" :style="{ padding: placeholderCoverPadding + 'rem' }">
|
|
|
|
<div>
|
|
|
|
<p class="text-center font-book" style="color: rgb(247 223 187)" :style="{ fontSize: titleFontSize + 'rem' }">{{ titleCleaned }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-if="!hasCover" class="absolute left-0 right-0 w-full flex items-center justify-center" :style="{ padding: placeholderCoverPadding + 'rem', bottom: authorBottom + 'rem' }">
|
2021-08-20 00:29:36 +02:00
|
|
|
<p class="text-center font-book" style="color: rgb(247 223 187); opacity: 0.75" :style="{ fontSize: authorFontSize + 'rem' }">{{ authorCleaned }}</p>
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
audiobook: {
|
|
|
|
type: Object,
|
|
|
|
default: () => {}
|
|
|
|
},
|
2021-08-25 03:24:40 +02:00
|
|
|
authorOverride: String,
|
2021-08-18 00:01:11 +02:00
|
|
|
width: {
|
|
|
|
type: Number,
|
|
|
|
default: 120
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
2021-08-21 20:02:24 +02:00
|
|
|
return {
|
|
|
|
imageFailed: false
|
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2021-08-25 03:24:40 +02:00
|
|
|
watch: {
|
|
|
|
cover() {
|
|
|
|
this.imageFailed = false
|
|
|
|
}
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
computed: {
|
|
|
|
book() {
|
|
|
|
return this.audiobook.book || {}
|
|
|
|
},
|
|
|
|
title() {
|
|
|
|
return this.book.title || 'No Title'
|
|
|
|
},
|
|
|
|
titleCleaned() {
|
2021-08-20 00:29:36 +02:00
|
|
|
if (this.title.length > 60) {
|
|
|
|
return this.title.slice(0, 57) + '...'
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
return this.title
|
|
|
|
},
|
|
|
|
author() {
|
2021-08-25 03:24:40 +02:00
|
|
|
if (this.authorOverride) return this.authorOverride
|
2021-08-18 00:01:11 +02:00
|
|
|
return this.book.author || 'Unknown'
|
|
|
|
},
|
2021-08-20 00:29:36 +02:00
|
|
|
authorCleaned() {
|
|
|
|
if (this.author.length > 30) {
|
|
|
|
return this.author.slice(0, 27) + '...'
|
|
|
|
}
|
|
|
|
return this.author
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
cover() {
|
|
|
|
return this.book.cover || '/book_placeholder.jpg'
|
|
|
|
},
|
|
|
|
hasCover() {
|
|
|
|
return !!this.book.cover
|
|
|
|
},
|
2021-08-21 20:02:24 +02:00
|
|
|
sizeMultiplier() {
|
2021-08-18 00:01:11 +02:00
|
|
|
return this.width / 120
|
|
|
|
},
|
|
|
|
titleFontSize() {
|
2021-08-21 20:02:24 +02:00
|
|
|
return 0.75 * this.sizeMultiplier
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
|
|
|
authorFontSize() {
|
2021-08-21 20:02:24 +02:00
|
|
|
return 0.6 * this.sizeMultiplier
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
|
|
|
placeholderCoverPadding() {
|
2021-08-21 20:02:24 +02:00
|
|
|
return 0.8 * this.sizeMultiplier
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
|
|
|
authorBottom() {
|
2021-08-21 20:02:24 +02:00
|
|
|
return 0.75 * this.sizeMultiplier
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
imageError(err) {
|
|
|
|
console.error('ImgError', err)
|
|
|
|
this.imageFailed = true
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
|
|
|
</script>
|