koel/resources/assets/js/components/album/AlbumInfo.vue

76 lines
2.3 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
2022-05-03 16:51:59 +00:00
<article :class="mode" class="album-info" data-testid="album-info">
2022-04-15 14:24:30 +00:00
<h1 class="name">
<span>{{ album.name }}</span>
<button :title="`Play all songs in ${album.name}`" class="control play" type="button" @click.prevent="play">
2022-06-10 10:47:46 +00:00
<i class="fa fa-play"/>
2022-04-15 14:24:30 +00:00
</button>
</h1>
<main>
<AlbumThumbnail :entity="album"/>
2022-04-15 14:24:30 +00:00
<template v-if="info">
<div v-if="info.wiki?.summary" class="wiki">
<div v-if="showSummary" class="summary" v-html="info.wiki.summary"/>
<div v-if="showFull" class="full" v-html="info.wiki.full"/>
2022-04-15 14:24:30 +00:00
2022-05-03 16:51:59 +00:00
<button v-if="showSummary" class="more" data-testid="more-btn" @click.prevent="showingFullWiki = true">
2022-04-15 14:24:30 +00:00
Full Wiki
</button>
</div>
<TrackList v-if="info.tracks?.length" :album="album" :tracks="info.tracks" data-testid="album-info-tracks"/>
2022-04-15 14:24:30 +00:00
<footer>
2022-06-10 10:47:46 +00:00
Data &copy;
<a :href="info.url" rel="noopener" target="_blank">Last.fm</a>
2022-06-10 10:47:46 +00:00
</footer>
2022-04-15 14:24:30 +00:00
</template>
</main>
</article>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
import { computed, defineAsyncComponent, ref, toRefs, watch } from 'vue'
2022-06-10 10:47:46 +00:00
import { useThirdPartyServices } from '@/composables'
import { songStore } from '@/stores'
import { playbackService } from '@/services'
import { mediaInfoService } from '@/services/mediaInfoService'
2022-04-15 14:24:30 +00:00
import AlbumThumbnail from '@/components/ui/AlbumArtistThumbnail.vue'
const TrackList = defineAsyncComponent(() => import('@/components/album/AlbumTrackList.vue'))
2022-04-15 14:24:30 +00:00
type DisplayMode = 'aside' | 'full'
2022-04-15 14:24:30 +00:00
const props = withDefaults(defineProps<{ album: Album, mode?: DisplayMode }>(), { mode: 'aside' })
2022-04-15 17:00:08 +00:00
const { album, mode } = toRefs(props)
2022-04-15 14:24:30 +00:00
const info = ref<AlbumInfo | null>(null)
2022-04-15 17:00:08 +00:00
const showingFullWiki = ref(false)
2022-04-15 14:24:30 +00:00
2022-06-10 10:47:46 +00:00
const { useLastfm } = useThirdPartyServices()
watch(album, async () => {
showingFullWiki.value = false
info.value = null
useLastfm.value && (info.value = await mediaInfoService.fetchForAlbum(album.value))
}, { immediate: true })
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const showSummary = computed(() => mode.value !== 'full' && !showingFullWiki.value)
const showFull = computed(() => !showSummary.value)
2022-04-15 14:24:30 +00:00
2022-06-10 10:47:46 +00:00
const play = async () => playbackService.queueAndPlay(await songStore.fetchForAlbum(album.value))
2022-04-15 14:24:30 +00:00
</script>
<style lang="scss">
.album-info {
@include artist-album-info();
.track-listing {
margin-top: 2rem;
}
2022-04-15 14:24:30 +00:00
}
</style>