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

192 lines
5.4 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<section id="artistWrapper">
2022-07-30 15:08:20 +00:00
<ScreenHeaderSkeleton v-if="loading"/>
<ScreenHeader v-if="!loading && artist" :layout="songs.length === 0 ? 'collapsed' : headerLayout">
2022-04-15 14:24:30 +00:00
{{ artist.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
<ArtistThumbnail :entity="artist"/>
2022-04-15 14:24:30 +00:00
</template>
<template v-slot:meta>
<span>{{ pluralize(albumCount, 'album') }}</span>
<span>{{ pluralize(songs, 'song') }}</span>
<span>{{ duration }}</span>
2022-07-10 17:15:56 +00:00
<a
v-if="allowDownload"
class="download"
href
role="button"
title="Download all songs by this artist"
@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
<ScreenTabs>
<template #header>
<label :class="{ active: activeTab === 'Songs' }">
Songs
<input type="radio" name="tab" value="Songs" v-model="activeTab"/>
</label>
<label :class="{ active: activeTab === 'Albums' }">
Albums
<input type="radio" name="tab" value="Albums" v-model="activeTab"/>
</label>
<label :class="{ active: activeTab === 'Info' }" v-if="useLastfm">
Information
<input type="radio" name="tab" value="Info" v-model="activeTab"/>
</label>
</template>
<div v-show="activeTab === 'Songs'" class="songs-pane">
<SongListSkeleton v-if="loading"/>
<SongList
v-else
ref="songList"
@sort="sort"
@press:enter="onPressEnter"
@scroll-breakpoint="onScrollBreakpoint"
/>
</div>
<div v-show="activeTab === 'Albums'" class="albums-pane">
<ul v-if="albums" class="as-list">
<li v-for="album in albums" :key="album.id">
<AlbumCard :album="album" layout="compact"/>
</li>
</ul>
<ul v-else class="as-list">
<li v-for="i in 12" :key="i">
<AlbumCardSkeleton layout="compact"/>
</li>
</ul>
</div>
2022-04-15 14:24:30 +00:00
<div v-show="activeTab === 'Info'" class="info-pane" v-if="useLastfm && artist">
2022-06-10 10:47:46 +00:00
<ArtistInfo :artist="artist" mode="full"/>
2022-04-15 14:24:30 +00:00
</div>
</ScreenTabs>
2022-04-15 14:24:30 +00:00
</section>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
import { computed, defineAsyncComponent, onMounted, ref, toRef, watch } from 'vue'
2022-11-18 18:44:20 +00:00
import { eventBus, logger, pluralize } from '@/utils'
import { albumStore, artistStore, commonStore, songStore } from '@/stores'
2022-06-10 10:47:46 +00:00
import { downloadService } from '@/services'
2022-11-18 18:44:20 +00:00
import { useDialogBox, useRouter, useSongList, useThirdPartyServices } from '@/composables'
2022-04-15 17:00:08 +00:00
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
import ArtistThumbnail 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'
import ScreenTabs from '@/components/ui/ArtistAlbumScreenTabs.vue'
2022-07-30 15:08:20 +00:00
const ArtistInfo = defineAsyncComponent(() => import('@/components/artist/ArtistInfo.vue'))
const AlbumCard = defineAsyncComponent(() => import('@/components/album/AlbumCard.vue'))
const AlbumCardSkeleton = defineAsyncComponent(() => import('@/components/ui/skeletons/ArtistAlbumCardSkeleton.vue'))
type Tab = 'Songs' | 'Albums' | 'Info'
const activeTab = ref<Tab>('Songs')
const { showErrorDialog } = useDialogBox()
2022-11-18 18:44:20 +00:00
const { getRouteParam, go } = useRouter()
2022-04-21 16:06:45 +00:00
const artistId = ref<number>()
2022-07-30 15:08:20 +00:00
const artist = ref<Artist>()
const songs = ref<Song[]>([])
const loading = ref(false)
let albums = ref<Album[] | undefined>()
let info = ref<ArtistInfo | undefined | null>()
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,
duration,
sort,
onPressEnter,
2022-04-15 17:00:08 +00:00
playAll,
playSelected,
2022-07-16 09:52:39 +00:00
onScrollBreakpoint
} = useSongList(songs)
2022-04-15 17:00:08 +00:00
const { useLastfm } = useThirdPartyServices()
2022-06-10 10:47:46 +00:00
const allowDownload = toRef(commonStore.state, 'allow_download')
2022-04-15 17:00:08 +00:00
const albumCount = computed(() => {
const albums = new Set()
songs.value.forEach(song => albums.add(song.album_id))
return albums.size
})
watch(activeTab, async tab => {
if (tab === 'Albums' && !albums.value) {
albums.value = await albumStore.fetchForArtist(artist.value!)
}
})
watch(artistId, async id => {
if (!id) return
2022-04-15 17:00:08 +00:00
2022-07-30 15:08:20 +00:00
loading.value = true
try {
[artist.value, songs.value] = await Promise.all([
artistStore.resolve(id),
songStore.fetchForArtist(id)
2022-07-30 15:08:20 +00:00
])
} catch (error) {
logger.error(error)
showErrorDialog('Failed to load artist. Please try again.', 'Error')
2022-07-30 15:08:20 +00:00
} finally {
loading.value = false
}
2022-06-10 10:47:46 +00:00
})
const download = () => downloadService.fromArtist(artist.value!)
2022-11-18 18:44:20 +00:00
onMounted(() => (artistId.value = parseInt(getRouteParam('id')!)))
// if the current artist has been deleted, go back to the list
2022-11-18 18:44:20 +00:00
eventBus.on('SONGS_UPDATED', () => artistStore.byId(artist.value!.id) || go('artists'))
2022-04-15 14:24:30 +00:00
</script>
<style lang="scss" scoped>
2022-07-04 15:57:08 +00:00
@import "#/partials/_mixins.scss";
2022-04-15 14:24:30 +00:00
#artistWrapper {
@include artist-album-info-wrapper();
}
.albums-pane {
padding: 1.8rem;
> ul {
@include artist-album-wrapper();
}
}
.info-pane {
padding: 1.8rem;
}
2022-04-15 14:24:30 +00:00
</style>