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 }}
|
2022-09-11 08:06:34 +00:00
|
|
|
<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-10-09 08:55:58 +00:00
|
|
|
<a v-if="isNormalArtist" :href="`#/artist/${album.artist_id}`" class="artist">{{ album.artist_name }}</a>
|
2022-10-08 10:54:25 +00:00
|
|
|
<span v-else class="nope">{{ album.artist_name }}</span>
|
2022-09-15 09:07:25 +00:00
|
|
|
<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 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-10-18 14:07:41 +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 === 'OtherAlbums' }">
|
|
|
|
Other Albums
|
|
|
|
<input type="radio" name="tab" value="OtherAlbums" 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'">
|
|
|
|
<SongListSkeleton v-if="loading"/>
|
|
|
|
<SongList
|
|
|
|
v-else
|
|
|
|
ref="songList"
|
|
|
|
@sort="sort"
|
|
|
|
@press:enter="onPressEnter"
|
|
|
|
@scroll-breakpoint="onScrollBreakpoint"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-show="activeTab === 'OtherAlbums'" class="albums-pane" data-testid="albums-pane">
|
|
|
|
<template v-if="otherAlbums">
|
|
|
|
<ul v-if="otherAlbums.length" class="as-list">
|
|
|
|
<li v-for="album in otherAlbums" :key="album.id">
|
|
|
|
<AlbumCard :album="album" layout="compact"/>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
<p v-else class="text-secondary">No other albums by {{ album.artist_name }} found in the library.</p>
|
|
|
|
</template>
|
|
|
|
<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
|
|
|
|
2022-10-18 14:07:41 +00:00
|
|
|
<div v-show="activeTab === 'Info'" class="info-pane" v-if="useLastfm && album">
|
2022-06-10 10:47:46 +00:00
|
|
|
<AlbumInfo :album="album" mode="full"/>
|
2022-04-15 14:24:30 +00:00
|
|
|
</div>
|
2022-10-18 14:07:41 +00:00
|
|
|
</ScreenTabs>
|
2022-04-15 14:24:30 +00:00
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<script lang="ts" setup>
|
2022-10-18 14:07:41 +00:00
|
|
|
import { computed, defineAsyncComponent, onMounted, ref, toRef, watch } from 'vue'
|
2022-09-15 09:07:25 +00:00
|
|
|
import { eventBus, logger, pluralize, requireInjection } from '@/utils'
|
2022-07-04 13:24:02 +00:00
|
|
|
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'
|
2022-10-08 10:54:25 +00:00
|
|
|
import { DialogBoxKey, RouterKey } from '@/symbols'
|
2022-04-15 17:00:08 +00:00
|
|
|
|
2022-07-07 18:05:46 +00:00
|
|
|
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
|
2022-07-10 16:39:05 +00:00
|
|
|
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-10-18 14:07:41 +00:00
|
|
|
import ScreenTabs from '@/components/ui/ArtistAlbumScreenTabs.vue'
|
|
|
|
|
|
|
|
type Tab = 'Songs' | 'OtherAlbums' | 'Info'
|
|
|
|
const activeTab = ref<Tab>('Songs')
|
2022-07-07 18:05:46 +00:00
|
|
|
|
2022-04-21 10:43:10 +00:00
|
|
|
const AlbumInfo = defineAsyncComponent(() => import('@/components/album/AlbumInfo.vue'))
|
2022-10-18 14:07:41 +00:00
|
|
|
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
|
|
|
|
2022-07-30 15:08:20 +00:00
|
|
|
const dialog = requireInjection(DialogBoxKey)
|
2022-10-08 10:54:25 +00:00
|
|
|
const router = requireInjection(RouterKey)
|
2022-04-21 16:06:45 +00:00
|
|
|
|
2022-10-18 14:07:41 +00:00
|
|
|
const albumId = ref<number>()
|
2022-07-30 15:08:20 +00:00
|
|
|
const album = ref<Album>()
|
|
|
|
const songs = ref<Song[]>([])
|
|
|
|
const loading = ref(false)
|
2022-10-18 14:07:41 +00:00
|
|
|
let otherAlbums = ref<Album[]>()
|
|
|
|
let info = ref<ArtistInfo | 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,
|
2022-09-15 09:07:25 +00:00
|
|
|
duration,
|
2022-09-16 12:10:09 +00:00
|
|
|
sort,
|
2022-04-21 18:12:11 +00:00
|
|
|
onPressEnter,
|
2022-04-15 17:00:08 +00:00
|
|
|
playAll,
|
|
|
|
playSelected,
|
2022-07-16 09:52:39 +00:00
|
|
|
onScrollBreakpoint
|
2022-11-12 21:38:31 +00:00
|
|
|
} = useSongList(songs)
|
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-10-08 10:54:25 +00:00
|
|
|
const download = () => downloadService.fromAlbum(album.value!)
|
2022-04-15 17:00:08 +00:00
|
|
|
|
2022-10-18 14:07:41 +00:00
|
|
|
watch(activeTab, async tab => {
|
|
|
|
if (tab === 'OtherAlbums' && !otherAlbums.value) {
|
|
|
|
const albums = await albumStore.fetchForArtist(album.value!.artist_id)
|
|
|
|
otherAlbums.value = albums.filter(a => a.id !== album.value!.id)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
watch(albumId, async id => {
|
|
|
|
if (!id) 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([
|
2022-10-08 10:54:25 +00:00
|
|
|
albumStore.resolve(id),
|
|
|
|
songStore.fetchForAlbum(id)
|
2022-07-30 15:08:20 +00:00
|
|
|
])
|
2022-09-16 12:10:09 +00:00
|
|
|
|
|
|
|
sort('track')
|
2022-10-18 14:07:41 +00:00
|
|
|
} catch (error) {
|
|
|
|
logger.error(error)
|
2022-07-30 15:08:20 +00:00
|
|
|
dialog.value.error('Failed to load album. Please try again.')
|
|
|
|
} finally {
|
|
|
|
loading.value = false
|
|
|
|
}
|
2022-06-10 10:47:46 +00:00
|
|
|
})
|
2022-07-04 13:24:02 +00:00
|
|
|
|
2022-10-18 14:07:41 +00:00
|
|
|
onMounted(async () => (albumId.value = parseInt(router.$currentRoute.value.params!.id)))
|
|
|
|
|
|
|
|
router.onRouteChanged(route => route.screen === 'Album' && (albumId.value = parseInt(route.params!.id)))
|
|
|
|
|
2022-10-08 10:54:25 +00:00
|
|
|
// if the current album has been deleted, go back to the list
|
2022-10-18 14:07:41 +00:00
|
|
|
eventBus.on('SONGS_UPDATED', () => albumStore.byId(albumId.value) || router.go('albums'))
|
2022-04-15 14:24:30 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
#albumWrapper {
|
|
|
|
@include artist-album-info-wrapper();
|
|
|
|
}
|
2022-10-18 14:07:41 +00:00
|
|
|
|
|
|
|
.albums-pane {
|
|
|
|
padding: 1.8rem;
|
|
|
|
|
|
|
|
> ul {
|
|
|
|
@include artist-album-wrapper();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.info-pane {
|
|
|
|
padding: 1.8rem;
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
</style>
|