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

141 lines
4.2 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<section id="albumWrapper">
2022-04-15 17:00:08 +00:00
<ScreenHeader>
2022-04-15 14:24:30 +00:00
{{ album.name }}
2022-04-15 17:00:08 +00:00
<ControlsToggler :showing-controls="showingControls" @toggleControls="toggleControls"/>
2022-04-15 14:24:30 +00:00
<template v-slot:thumbnail>
2022-04-15 17:00:08 +00:00
<AlbumThumbnail :entity="album"/>
2022-04-15 14:24:30 +00:00
</template>
<template v-slot:meta>
<span v-if="album.songs.length">
by
<a class="artist" v-if="isNormalArtist" :href="`#!/artist/${album.artist.id}`">{{ album.artist.name }}</a>
<span class="nope" v-else>{{ album.artist.name }}</span>
2022-04-15 17:00:08 +00:00
{{ pluralize(album.songs.length, 'song') }}
2022-04-15 14:24:30 +00:00
{{ fmtLength }}
<template v-if="sharedState.useLastfm">
<a class="info" href @click.prevent="showInfo" title="View album's extra information">Info</a>
</template>
<template v-if="sharedState.allowDownload">
<a class="download" href @click.prevent="download" title="Download all songs in album" role="button">
Download All
</a>
</template>
</span>
</template>
<template v-slot:controls>
2022-04-15 17:00:08 +00:00
<SongListControls
2022-04-15 14:24:30 +00:00
v-if="album.songs.length && (!isPhone || showingControls)"
@playAll="playAll"
@playSelected="playSelected"
:songs="album.songs"
:config="songListControlConfig"
:selectedSongs="selectedSongs"
/>
</template>
2022-04-15 17:00:08 +00:00
</ScreenHeader>
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
<SongList :items="album.songs" type="album" :config="listConfig" ref="songList"/>
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
<section class="info-wrapper" v-if="sharedState.useLastfm && showing">
<CloseModalBtn @click="showing = false"/>
2022-04-15 14:24:30 +00:00
<div class="inner">
2022-04-15 17:00:08 +00:00
<div class="loading" v-if="loading">
<SoundBar/>
2022-04-15 14:24:30 +00:00
</div>
2022-04-15 17:00:08 +00:00
<AlbumInfo :album="album" mode="full" v-else/>
2022-04-15 14:24:30 +00:00
</div>
</section>
</section>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
import { computed, defineAsyncComponent, reactive, ref, toRefs, watch } from 'vue'
2022-04-15 14:24:30 +00:00
import { pluralize } from '@/utils'
import { artistStore, sharedStore } from '@/stores'
2022-04-15 17:00:08 +00:00
import { albumInfo as albumInfoService, download as downloadService } from '@/services'
2022-04-15 14:24:30 +00:00
import router from '@/router'
2022-04-15 17:00:08 +00:00
import { useAlbumAttributes, useSongList } from '@/composables'
const ScreenHeader = defineAsyncComponent(() => import('@/components/ui/screen-header.vue'))
const AlbumInfo = defineAsyncComponent(() => import('@/components/album/info.vue'))
const SoundBar = defineAsyncComponent(() => import('@/components/ui/sound-bar.vue'))
const AlbumThumbnail = defineAsyncComponent(() => import('@/components/ui/album-artist-thumbnail.vue'))
const CloseModalBtn = defineAsyncComponent(() => import('@/components/ui/close-modal-btn.vue'))
const {
SongList,
SongListControls,
ControlsToggler,
songList,
selectedSongs,
showingControls,
songListControlConfig,
isPhone,
playAll,
playSelected,
toggleControls
} = useSongList()
const props = defineProps<{ album: Album }>()
const { album } = toRefs(props)
const { length, fmtLength } = useAlbumAttributes(album.value)
const listConfig: Partial<SongListConfig> = { columns: ['track', 'title', 'length'] }
const sharedState = reactive(sharedStore.state)
const showing = ref(false)
const loading = ref(true)
const isNormalArtist = computed(() => {
return !artistStore.isVariousArtists(album.value.artist) && !artistStore.isUnknownArtist(album.value.artist)
})
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
/**
* Watch the album's song count.
* If this is changed to 0, the user has edited the songs on this album
* and moved all of them into another album.
* We should then go back to the album list.
*/
watch(() => album.value.songs.length, newSongCount => newSongCount || router.go('albums'))
watch(album, () => {
showing.value = false
// @ts-ignore
songList.value?.sort()
})
const download = () => downloadService.fromAlbum(album.value)
const showInfo = async () => {
showing.value = true
if (!album.value.info) {
try {
await albumInfoService.fetch(album.value)
} catch (e) {
/* eslint no-console: 0 */
console.error(e)
} finally {
loading.value = false
2022-04-15 14:24:30 +00:00
}
2022-04-15 17:00:08 +00:00
} else {
loading.value = false
2022-04-15 14:24:30 +00:00
}
2022-04-15 17:00:08 +00:00
}
2022-04-15 14:24:30 +00:00
</script>
<style lang="scss" scoped>
#albumWrapper {
@include artist-album-info-wrapper();
}
</style>