[web-src] Always show cover artwork in album dialog

If no artwork is available or not yet loaded, falls back to the
generated cover artwork. Avoids jumping of dialog after loading of
remote image finished.
This commit is contained in:
chme 2020-04-20 19:09:07 +02:00
parent f2d4b88c12
commit fe0ca815a7
4 changed files with 50 additions and 36 deletions

View File

@ -1,14 +1,27 @@
<template> <template>
<img :src="dataURI" :alt="alt_text"> <figure>
<img
v-show="artwork_visible"
:src="artwork_url_with_size"
@load="artwork_loaded"
@error="artwork_error"
@click="$emit('click')">
<img
v-show="!artwork_visible"
:src="dataURI"
:alt="alt_text"
@click="$emit('click')">
</figure>
</template> </template>
<script> <script>
import webapi from '@/webapi'
import SVGRenderer from '@/lib/SVGRenderer' import SVGRenderer from '@/lib/SVGRenderer'
import stringToColor from 'string-to-color' import stringToColor from 'string-to-color'
export default { export default {
name: 'CoverPlaceholder', name: 'CoverArtwork',
props: ['artist', 'album'], props: ['artist', 'album', 'artwork_url'],
data () { data () {
return { return {
@ -17,11 +30,17 @@ export default {
height: 600, height: 600,
font_family: 'sans-serif', font_family: 'sans-serif',
font_size: 200, font_size: 200,
font_weight: 600 font_weight: 600,
artwork_visible: false
} }
}, },
computed: { computed: {
artwork_url_with_size: function () {
return webapi.artwork_url_append_size_params(this.artwork_url)
},
alt_text () { alt_text () {
return this.artist + ' - ' + this.album return this.artist + ' - ' + this.album
}, },
@ -76,6 +95,16 @@ export default {
dataURI () { dataURI () {
return this.svg.render(this.rendererParams) return this.svg.render(this.rendererParams)
} }
},
methods: {
artwork_loaded: function () {
this.artwork_visible = true
},
artwork_error: function () {
this.artwork_visible = false
}
} }
} }
</script> </script>

View File

@ -6,14 +6,16 @@
<div class="modal-content fd-modal-card"> <div class="modal-content fd-modal-card">
<div class="card"> <div class="card">
<div class="card-content"> <div class="card-content">
<figure class="image is-square fd-has-margin-bottom" v-show="artwork_visible"> <cover-artwork
<img :src="artwork_url" @load="artwork_loaded" @error="artwork_error" class="fd-has-shadow"> :artwork_url="album.artwork_url"
</figure> :artist="album.artist"
:album="album.name"
class="image is-square fd-has-margin-bottom fd-has-shadow" />
<p class="title is-4"> <p class="title is-4">
<a class="has-text-link" @click="open_album">{{ album.name }}</a> <a class="has-text-link" @click="open_album">{{ album.name }}</a>
</p> </p>
<div class="buttons" v-if="media_kind === 'podcast'"> <div class="buttons" v-if="media_kind === 'podcast'">
<a class="button is-small" v-if="new_tracks > 0" @click="mark_played">Mark as played</a> <a class="button is-small" @click="mark_played">Mark as played</a>
<a class="button is-small" @click="$emit('remove_podcast')">Remove podcast</a> <a class="button is-small" @click="$emit('remove_podcast')">Remove podcast</a>
</div> </div>
<div class="content is-small"> <div class="content is-small">
@ -51,10 +53,12 @@
</template> </template>
<script> <script>
import CoverArtwork from '@/components/CoverArtwork'
import webapi from '@/webapi' import webapi from '@/webapi'
export default { export default {
name: 'ModalDialogAlbum', name: 'ModalDialogAlbum',
components: { CoverArtwork },
props: ['show', 'album', 'media_kind', 'new_tracks'], props: ['show', 'album', 'media_kind', 'new_tracks'],
data () { data () {

View File

@ -113,6 +113,7 @@ section.fd-tabs-section + section.fd-content {
height: calc(100vh - 3.25rem - 3.25rem); height: calc(100vh - 3.25rem - 3.25rem);
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: center;
} }
.fd-is-fullheight .fd-is-expanded { .fd-is-fullheight .fd-is-expanded {
@ -131,6 +132,7 @@ section.fd-tabs-section + section.fd-content {
width: 100%; width: 100%;
height: 100%; height: 100%;
object-fit: contain; object-fit: contain;
object-position: bottom;
filter: drop-shadow(0px 0px 1px rgba(0,0,0,.3)) drop-shadow(0px 0px 10px rgba(0,0,0,.3)); filter: drop-shadow(0px 0px 1px rgba(0,0,0,.3)) drop-shadow(0px 0px 10px rgba(0,0,0,.3));
} }

View File

@ -2,19 +2,11 @@
<section> <section>
<div v-if="now_playing.id > 0" class="fd-is-fullheight"> <div v-if="now_playing.id > 0" class="fd-is-fullheight">
<div class="fd-is-expanded"> <div class="fd-is-expanded">
<figure @click="open_dialog(now_playing)" class="fd-cover-image"> <cover-artwork @click="open_dialog(now_playing)"
<img :artwork_url="now_playing.artwork_url"
v-show="artwork_visible"
:src="artwork_url"
class="fd-has-action"
@load="artwork_loaded"
@error="artwork_error">
<cover-placeholder
v-show="!artwork_visible"
:artist="now_playing.artist" :artist="now_playing.artist"
:album="now_playing.album" :album="now_playing.album"
class="fd-has-action" /> class="fd-cover-image fd-has-action" />
</figure>
</div> </div>
<div class="fd-has-padding-left-right"> <div class="fd-has-padding-left-right">
<div class="container has-text-centered"> <div class="container has-text-centered">
@ -68,19 +60,18 @@
<script> <script>
import ModalDialogQueueItem from '@/components/ModalDialogQueueItem' import ModalDialogQueueItem from '@/components/ModalDialogQueueItem'
import RangeSlider from 'vue-range-slider' import RangeSlider from 'vue-range-slider'
import CoverPlaceholder from '@/components/CoverPlaceholder' import CoverArtwork from '@/components/CoverArtwork'
import webapi from '@/webapi' import webapi from '@/webapi'
import * as types from '@/store/mutation_types' import * as types from '@/store/mutation_types'
export default { export default {
name: 'PageNowPlaying', name: 'PageNowPlaying',
components: { ModalDialogQueueItem, RangeSlider, CoverPlaceholder }, components: { ModalDialogQueueItem, RangeSlider, CoverArtwork },
data () { data () {
return { return {
item_progress_ms: 0, item_progress_ms: 0,
interval_id: 0, interval_id: 0,
artwork_visible: false,
show_details_modal: false, show_details_modal: false,
selected_item: {} selected_item: {}
@ -113,10 +104,6 @@ export default {
return this.$store.getters.now_playing return this.$store.getters.now_playing
}, },
artwork_url: function () {
return webapi.artwork_url_append_size_params(this.now_playing.artwork_url)
},
settings_option_show_composer_now_playing () { settings_option_show_composer_now_playing () {
return this.$store.getters.settings_option_show_composer_now_playing return this.$store.getters.settings_option_show_composer_now_playing
}, },
@ -150,14 +137,6 @@ export default {
}) })
}, },
artwork_loaded: function () {
this.artwork_visible = true
},
artwork_error: function () {
this.artwork_visible = false
},
open_dialog: function (item) { open_dialog: function (item) {
this.selected_item = item this.selected_item = item
this.show_details_modal = true this.show_details_modal = true