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

188 lines
6.1 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
2024-04-04 22:20:42 +00:00
<ScreenBase v-if="album">
<template #header>
<ScreenHeaderSkeleton v-if="loading" />
2022-07-30 15:08:20 +00:00
2024-04-04 22:20:42 +00:00
<ScreenHeader v-if="!loading && album" :layout="songs.length === 0 ? 'collapsed' : headerLayout">
{{ album.name }}
<ControlsToggle v-model="showingControls" />
2022-04-15 14:24:30 +00:00
2024-04-04 22:20:42 +00:00
<template #thumbnail>
<AlbumThumbnail :entity="album" />
</template>
2022-04-15 14:24:30 +00:00
2024-04-04 22:20:42 +00:00
<template #meta>
<a v-if="isNormalArtist" :href="`#/artist/${album.artist_id}`" class="artist">{{ album.artist_name }}</a>
<span v-else class="nope">{{ album.artist_name }}</span>
2024-05-19 05:49:42 +00:00
<span>{{ pluralize(songs, 'item') }}</span>
2024-04-04 22:20:42 +00:00
<span>{{ duration }}</span>
2022-07-10 17:15:56 +00:00
2024-04-04 22:20:42 +00:00
<a
v-if="downloadable"
2024-04-04 22:20:42 +00:00
class="download"
role="button"
title="Download all songs in album"
@click.prevent="download"
>
Download All
</a>
</template>
2022-04-15 14:24:30 +00:00
2024-04-04 22:20:42 +00:00
<template #controls>
<SongListControls
v-if="songs.length && (!isPhone || showingControls)"
:config="config"
@filter="applyFilter"
@play-all="playAll"
@play-selected="playSelected"
/>
</template>
</ScreenHeader>
</template>
2022-04-15 14:24:30 +00:00
2024-04-04 22:20:42 +00:00
<ScreenTabs class="-m-6">
<template #header>
<label :class="{ active: activeTab === 'Songs' }">
Songs
2024-04-23 21:01:27 +00:00
<input v-model="activeTab" name="tab" type="radio" value="Songs">
</label>
<label :class="{ active: activeTab === 'OtherAlbums' }">
Other Albums
2024-04-23 21:01:27 +00:00
<input v-model="activeTab" name="tab" type="radio" value="OtherAlbums">
</label>
2022-12-02 16:17:37 +00:00
<label v-if="useLastfm" :class="{ active: activeTab === 'Info' }">
Information
2024-04-23 21:01:27 +00:00
<input v-model="activeTab" name="tab" type="radio" value="Info">
</label>
</template>
<div v-show="activeTab === 'Songs'" class="songs-pane">
2022-12-02 16:17:37 +00:00
<SongListSkeleton v-if="loading" />
<SongList
v-else
ref="songList"
@press:enter="onPressEnter"
@scroll-breakpoint="onScrollBreakpoint"
/>
</div>
<div v-show="activeTab === 'OtherAlbums'" class="albums-pane" data-testid="albums-pane">
<template v-if="otherAlbums">
2024-04-04 22:20:42 +00:00
<AlbumGrid v-if="otherAlbums.length" v-koel-overflow-fade view-mode="list">
2024-04-23 21:01:27 +00:00
<AlbumCard v-for="otherAlbum in otherAlbums" :key="otherAlbum.id" :album="otherAlbum" layout="compact" />
2024-04-04 22:20:42 +00:00
</AlbumGrid>
<p v-else class="text-k-text-secondary p-6">
No other albums by {{ album.artist_name }} found in the library.
</p>
</template>
2024-04-04 22:20:42 +00:00
<AlbumGrid v-else view-mode="list">
<AlbumCardSkeleton v-for="i in 6" :key="i" layout="compact" />
</AlbumGrid>
</div>
2022-04-15 14:24:30 +00:00
2024-04-23 21:01:27 +00:00
<div v-if="useLastfm && album" v-show="activeTab === 'Info'" class="info-pane">
2022-12-02 16:17:37 +00:00
<AlbumInfo :album="album" mode="full" />
2022-04-15 14:24:30 +00:00
</div>
</ScreenTabs>
2024-04-04 22:20:42 +00:00
</ScreenBase>
2022-04-15 14:24:30 +00:00
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
2023-08-20 22:35:58 +00:00
import { computed, defineAsyncComponent, ref, toRef, watch } from 'vue'
import { eventBus, pluralize } from '@/utils'
import { albumStore, artistStore, commonStore, songStore } from '@/stores'
2022-06-10 10:47:46 +00:00
import { downloadService } from '@/services'
import { useErrorHandler, useRouter, useSongList, useSongListControls } from '@/composables'
2022-04-15 17:00:08 +00:00
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
2024-04-29 19:50:03 +00:00
import AlbumThumbnail from '@/components/ui/album-artist/AlbumOrArtistThumbnail.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'
2024-04-04 22:20:42 +00:00
import ScreenBase from '@/components/screens/ScreenBase.vue'
import AlbumGrid from '@/components/ui/album-artist/AlbumOrArtistGrid.vue'
type Tab = 'Songs' | 'OtherAlbums' | 'Info'
const activeTab = ref<Tab>('Songs')
2022-04-21 10:43:10 +00:00
const AlbumInfo = defineAsyncComponent(() => import('@/components/album/AlbumInfo.vue'))
const AlbumCard = defineAsyncComponent(() => import('@/components/album/AlbumCard.vue'))
const AlbumCardSkeleton = defineAsyncComponent(() => import('@/components/ui/skeletons/ArtistAlbumCardSkeleton.vue'))
2022-04-15 17:00:08 +00:00
2023-08-20 22:35:58 +00:00
const { getRouteParam, go, onScreenActivated } = useRouter()
2022-04-21 16:06:45 +00:00
const albumId = ref<number>()
2024-03-25 22:59:38 +00:00
const album = ref<Album | undefined>()
2022-07-30 15:08:20 +00:00
const songs = ref<Song[]>([])
const loading = ref(false)
2024-03-25 22:59:38 +00:00
let otherAlbums = ref<Album[] | undefined>()
let info = ref<ArtistInfo | undefined>()
2022-06-10 10:47:46 +00:00
2022-04-15 17:00:08 +00:00
const {
SongList,
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,
downloadable,
duration,
2024-03-25 22:59:38 +00:00
context,
sort,
onPressEnter,
2022-04-15 17:00:08 +00:00
playAll,
playSelected,
applyFilter,
2022-07-16 09:52:39 +00:00
onScrollBreakpoint
2024-03-25 22:59:38 +00:00
} = useSongList(songs, { type: 'Album' })
2022-04-15 17:00:08 +00:00
2024-01-18 11:13:05 +00:00
const { SongListControls, config } = useSongListControls('Album')
2024-01-04 11:35:36 +00:00
const useLastfm = toRef(commonStore.state, 'uses_last_fm')
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
const download = () => downloadService.fromAlbum(album.value!)
2022-04-15 17:00:08 +00:00
watch(activeTab, async tab => {
if (tab === 'OtherAlbums' && !otherAlbums.value) {
const albums = await albumStore.fetchForArtist(album.value!.artist_id)
2024-01-24 22:39:47 +00:00
otherAlbums.value = albums.filter(({ id }) => id !== album.value!.id)
}
})
watch(albumId, async id => {
2023-08-20 22:35:58 +00:00
if (!id || loading.value) return
album.value = undefined
info.value = undefined
otherAlbums.value = undefined
activeTab.value = 'Songs'
2022-07-30 15:08:20 +00:00
loading.value = true
try {
[album.value, songs.value] = await Promise.all([
albumStore.resolve(id),
songStore.fetchForAlbum(id)
2022-07-30 15:08:20 +00:00
])
2024-03-25 22:59:38 +00:00
context.entity = album.value
sort('track')
} catch (error: unknown) {
useErrorHandler('dialog').handleHttpError(error)
2022-07-30 15:08:20 +00:00
} finally {
loading.value = false
}
2022-06-10 10:47:46 +00:00
})
2023-08-20 22:35:58 +00:00
onScreenActivated('Album', () => (albumId.value = parseInt(getRouteParam('id')!)))
// if the current album has been deleted, go back to the list
2022-12-02 16:17:37 +00:00
eventBus.on('SONGS_UPDATED', () => albumStore.byId(albumId.value!) || go('albums'))
2022-04-15 14:24:30 +00:00
</script>