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

97 lines
3.3 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
2024-04-04 22:20:42 +00:00
<ScreenBase>
<template #header>
<ScreenHeader layout="collapsed">
Artists
<template #controls>
<ViewModeSwitch v-model="viewMode" />
</template>
</ScreenHeader>
</template>
2022-04-15 14:24:30 +00:00
<ScreenEmptyState v-if="libraryEmpty">
<template #icon>
<Icon :icon="faMicrophoneSlash" />
</template>
No artists found.
<span class="secondary d-block">
{{ isAdmin ? 'Have you set up your library yet?' : 'Contact your administrator to set up your library.' }}
</span>
</ScreenEmptyState>
2024-04-04 22:20:42 +00:00
<div v-else ref="gridContainer" v-koel-overflow-fade class="-m-6 overflow-auto">
<ArtistGrid :view-mode="viewMode" data-testid="artist-list">
<template v-if="showSkeletons">
<ArtistCardSkeleton v-for="i in 10" :key="i" :layout="itemLayout" />
</template>
<template v-else>
<ArtistCard v-for="artist in artists" :key="artist.id" :artist="artist" :layout="itemLayout" />
<ToTopButton />
</template>
</ArtistGrid>
2022-04-15 14:24:30 +00:00
</div>
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>
import { faMicrophoneSlash } from '@fortawesome/free-solid-svg-icons'
import { computed, ref, toRef, watch } from 'vue'
import { artistStore, commonStore, preferenceStore as preferences } from '@/stores'
import { useAuthorization, useInfiniteScroll, useMessageToaster, useRouter } from '@/composables'
import { logger } from '@/utils'
2022-04-15 14:24:30 +00:00
import ArtistCard from '@/components/artist/ArtistCard.vue'
2022-07-30 15:08:20 +00:00
import ArtistCardSkeleton from '@/components/ui/skeletons/ArtistAlbumCardSkeleton.vue'
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
import ViewModeSwitch from '@/components/ui/ViewModeSwitch.vue'
import ScreenEmptyState from '@/components/ui/ScreenEmptyState.vue'
2024-04-04 22:20:42 +00:00
import ScreenBase from '@/components/screens/ScreenBase.vue'
import ArtistGrid from '@/components/ui/album-artist/AlbumOrArtistGrid.vue'
const { isAdmin } = useAuthorization()
2022-04-15 14:24:30 +00:00
2024-04-04 22:20:42 +00:00
const gridContainer = ref<HTMLDivElement>()
2022-04-15 17:00:08 +00:00
const viewMode = ref<ArtistAlbumViewMode>('thumbnails')
const artists = toRef(artistStore.state, 'artists')
2022-04-15 14:24:30 +00:00
2022-06-10 10:47:46 +00:00
const {
ToTopButton,
makeScrollable
2024-04-04 22:20:42 +00:00
} = useInfiniteScroll(gridContainer, async () => await fetchArtists())
2022-06-10 10:47:46 +00:00
watch(viewMode, () => preferences.artists_view_mode = viewMode.value)
2022-04-15 14:24:30 +00:00
2022-06-10 10:47:46 +00:00
let initialized = false
2022-07-30 15:08:20 +00:00
const loading = ref(false)
2022-06-10 10:47:46 +00:00
const page = ref<number | null>(1)
2022-07-30 15:08:20 +00:00
const libraryEmpty = computed(() => commonStore.state.song_length === 0)
2022-07-30 15:08:20 +00:00
const itemLayout = computed<ArtistAlbumCardLayout>(() => viewMode.value === 'thumbnails' ? 'full' : 'compact')
2022-06-10 10:47:46 +00:00
const moreArtistsAvailable = computed(() => page.value !== null)
2022-07-30 15:08:20 +00:00
const showSkeletons = computed(() => loading.value && artists.value.length === 0)
2022-06-10 10:47:46 +00:00
const fetchArtists = async () => {
2022-07-30 15:08:20 +00:00
if (loading.value || !moreArtistsAvailable.value) return
2022-06-10 10:47:46 +00:00
2022-07-30 15:08:20 +00:00
loading.value = true
2022-07-22 22:03:25 +00:00
page.value = await artistStore.paginate(page.value!)
2022-07-30 15:08:20 +00:00
loading.value = false
2022-06-10 10:47:46 +00:00
}
2022-11-18 18:56:21 +00:00
useRouter().onScreenActivated('Artists', async () => {
if (libraryEmpty.value) return
if (!initialized) {
viewMode.value = preferences.artists_view_mode || 'thumbnails'
2022-06-10 10:47:46 +00:00
initialized = true
try {
await makeScrollable()
2024-04-04 22:20:42 +00:00
} catch (error: any) {
logger.error(error)
2024-04-04 22:20:42 +00:00
useMessageToaster().toastError(error.response.data?.message || 'Failed to load artists.')
initialized = false
}
2022-04-15 14:24:30 +00:00
}
})
</script>