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

131 lines
4 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<section id="albumWrapper">
2022-07-30 15:08:20 +00:00
<ScreenHeaderSkeleton v-if="loading"/>
<ScreenHeader v-if="!loading && album" :layout="songs.length === 0 ? 'collapsed' : headerLayout">
2022-04-15 14:24:30 +00:00
{{ album.name }}
<ControlsToggle v-model="showingControls"/>
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>
2022-07-10 17:15:56 +00:00
<a v-if="isNormalArtist" :href="`#!/artist/${album.artist_id}`" class="artist">{{ album.artist_name }}</a>
<span class="nope" v-else>{{ album.artist_name }}</span>
<span>{{ pluralize(album.song_count, 'song') }}</span>
<span>{{ secondsToHis(album.length) }}</span>
2022-07-10 17:33:53 +00:00
<a v-if="useLastfm" class="info" href title="View album information" @click.prevent="showInfo">Info</a>
2022-07-10 17:15:56 +00:00
<a
v-if="allowDownload"
class="download"
href role="button"
title="Download all songs in album"
@click.prevent="download"
>
Download All
</a>
2022-04-15 14:24:30 +00:00
</template>
<template v-slot:controls>
2022-04-15 17:00:08 +00:00
<SongListControls
2022-04-21 16:06:45 +00:00
v-if="songs.length && (!isPhone || showingControls)"
@playAll="playAll"
@playSelected="playSelected"
2022-04-15 14:24:30 +00:00
/>
</template>
2022-04-15 17:00:08 +00:00
</ScreenHeader>
2022-04-15 14:24:30 +00:00
2022-07-30 15:08:20 +00:00
<SongListSkeleton v-if="loading"/>
<SongList v-else ref="songList" @press:enter="onPressEnter" @scroll-breakpoint="onScrollBreakpoint"/>
2022-04-15 14:24:30 +00:00
2022-07-30 15:08:20 +00:00
<section v-if="!loading && useLastfm && showingInfo" class="info-wrapper">
<CloseModalBtn class="close-modal" @click="showingInfo = false"/>
2022-04-15 14:24:30 +00:00
<div class="inner">
2022-06-10 10:47:46 +00:00
<AlbumInfo :album="album" mode="full"/>
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, onMounted, ref, toRef, toRefs } from 'vue'
2022-07-30 15:08:20 +00:00
import { eventBus, logger, pluralize, requireInjection, secondsToHis } from '@/utils'
import { albumStore, artistStore, commonStore, songStore } from '@/stores'
2022-06-10 10:47:46 +00:00
import { downloadService } from '@/services'
2022-04-23 21:24:02 +00:00
import { useSongList } from '@/composables'
import router from '@/router'
2022-07-30 15:08:20 +00:00
import { DialogBoxKey } from '@/symbols'
2022-04-15 17:00:08 +00:00
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
import AlbumThumbnail from '@/components/ui/AlbumArtistThumbnail.vue'
2022-07-30 15:08:20 +00:00
import ScreenHeaderSkeleton from '@/components/ui/skeletons/ScreenHeaderSkeleton.vue'
import SongListSkeleton from '@/components/ui/skeletons/SongListSkeleton.vue'
2022-04-21 10:43:10 +00:00
const AlbumInfo = defineAsyncComponent(() => import('@/components/album/AlbumInfo.vue'))
2022-04-24 08:29:14 +00:00
const CloseModalBtn = defineAsyncComponent(() => import('@/components/ui/BtnCloseModal.vue'))
2022-04-15 17:00:08 +00:00
2022-07-30 15:08:20 +00:00
const dialog = requireInjection(DialogBoxKey)
const props = defineProps<{ album: number }>()
const { album: id } = toRefs(props)
2022-04-21 16:06:45 +00:00
2022-07-30 15:08:20 +00:00
const album = ref<Album>()
const songs = ref<Song[]>([])
const showingInfo = ref(false)
const loading = ref(false)
2022-06-10 10:47:46 +00:00
2022-04-15 17:00:08 +00:00
const {
SongList,
SongListControls,
2022-06-10 10:47:46 +00:00
ControlsToggle,
2022-07-16 09:52:39 +00:00
headerLayout,
2022-04-15 17:00:08 +00:00
songList,
showingControls,
isPhone,
onPressEnter,
2022-04-15 17:00:08 +00:00
playAll,
playSelected,
2022-07-16 09:52:39 +00:00
onScrollBreakpoint
2022-07-30 15:08:20 +00:00
} = useSongList(songs, 'album', { columns: ['track', 'title', 'artist', 'length'] })
2022-04-15 17:00:08 +00:00
2022-06-10 10:47:46 +00:00
const useLastfm = toRef(commonStore.state, 'use_last_fm')
const allowDownload = toRef(commonStore.state, 'allow_download')
2022-04-15 17:00:08 +00:00
const isNormalArtist = computed(() => {
2022-07-30 15:08:20 +00:00
if (!album.value) return true
2022-06-10 10:47:46 +00:00
return !artistStore.isVarious(album.value.artist_id) && !artistStore.isUnknown(album.value.artist_id)
2022-04-15 17:00:08 +00:00
})
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const download = () => downloadService.fromAlbum(album.value)
2022-06-10 10:47:46 +00:00
const showInfo = () => (showingInfo.value = true)
2022-04-15 17:00:08 +00:00
2022-06-10 10:47:46 +00:00
onMounted(async () => {
2022-07-30 15:08:20 +00:00
loading.value = true
try {
[album.value, songs.value] = await Promise.all([
albumStore.resolve(id.value),
songStore.fetchForAlbum(id.value)
])
} catch (e) {
logger.error(e)
dialog.value.error('Failed to load album. Please try again.')
} finally {
loading.value = false
}
2022-06-10 10:47:46 +00:00
})
eventBus.on('SONGS_UPDATED', () => {
// if the current album has been deleted, go back to the list
2022-07-30 15:08:20 +00:00
albumStore.byId(id.value) || router.go('albums')
})
2022-04-15 14:24:30 +00:00
</script>
<style lang="scss" scoped>
#albumWrapper {
@include artist-album-info-wrapper();
}
</style>