2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
|
|
|
<section id="artistsWrapper">
|
2022-07-16 15:44:45 +00:00
|
|
|
<ScreenHeader layout="collapsed">
|
2022-04-15 14:24:30 +00:00
|
|
|
Artists
|
2022-12-02 16:17:37 +00:00
|
|
|
<template #controls>
|
|
|
|
<ViewModeSwitch v-model="viewMode" />
|
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
|
|
|
|
2023-12-28 22:32:58 +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>
|
|
|
|
|
2022-07-11 17:30:51 +00:00
|
|
|
<div
|
2023-12-28 22:32:58 +00:00
|
|
|
v-else
|
2024-03-16 18:11:08 +00:00
|
|
|
ref="listEl"
|
2022-12-06 12:14:45 +00:00
|
|
|
v-koel-overflow-fade
|
2022-07-11 17:30:51 +00:00
|
|
|
:class="`as-${viewMode}`"
|
2024-04-04 20:13:35 +00:00
|
|
|
class="artists main-scroll-wrap artist-album-wrapper"
|
2022-07-11 17:30:51 +00:00
|
|
|
data-testid="artist-list"
|
|
|
|
>
|
2022-07-30 15:08:20 +00:00
|
|
|
<template v-if="showSkeletons">
|
2022-12-02 16:17:37 +00:00
|
|
|
<ArtistCardSkeleton v-for="i in 10" :key="i" :layout="itemLayout" />
|
2022-07-30 15:08:20 +00:00
|
|
|
</template>
|
|
|
|
<template v-else>
|
2022-12-02 16:17:37 +00:00
|
|
|
<ArtistCard v-for="artist in artists" :key="artist.id" :artist="artist" :layout="itemLayout" />
|
|
|
|
<ToTopButton />
|
2022-07-30 15:08:20 +00:00
|
|
|
</template>
|
2022-04-15 14:24:30 +00:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<script lang="ts" setup>
|
2023-12-28 22:32:58 +00:00
|
|
|
import { faMicrophoneSlash } from '@fortawesome/free-solid-svg-icons'
|
2022-07-07 18:05:46 +00:00
|
|
|
import { computed, ref, toRef, watch } from 'vue'
|
2023-12-28 22:32:58 +00:00
|
|
|
import { artistStore, commonStore, preferenceStore as preferences } from '@/stores'
|
|
|
|
import { useAuthorization, useInfiniteScroll, useMessageToaster, useRouter } from '@/composables'
|
2022-12-15 14:09:44 +00:00
|
|
|
import { logger } from '@/utils'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-07 18:05:46 +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'
|
2022-07-07 18:05:46 +00:00
|
|
|
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
|
|
|
|
import ViewModeSwitch from '@/components/ui/ViewModeSwitch.vue'
|
2023-12-28 22:32:58 +00:00
|
|
|
import ScreenEmptyState from '@/components/ui/ScreenEmptyState.vue'
|
|
|
|
|
|
|
|
const { isAdmin } = useAuthorization()
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2024-03-16 18:11:08 +00:00
|
|
|
const listEl = ref<HTMLElement | null>(null)
|
2022-04-15 17:00:08 +00:00
|
|
|
const viewMode = ref<ArtistAlbumViewMode>('thumbnails')
|
2022-05-16 07:34:18 +00:00
|
|
|
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-03-16 18:11:08 +00:00
|
|
|
} = useInfiniteScroll(listEl, async () => await fetchArtists())
|
2022-06-10 10:47:46 +00:00
|
|
|
|
2024-01-23 22:50:50 +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
|
|
|
|
2023-12-28 22:32:58 +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 () => {
|
2023-12-28 22:32:58 +00:00
|
|
|
if (libraryEmpty.value) return
|
2022-09-12 15:33:41 +00:00
|
|
|
if (!initialized) {
|
2024-01-23 22:50:50 +00:00
|
|
|
viewMode.value = preferences.artists_view_mode || 'thumbnails'
|
2022-06-10 10:47:46 +00:00
|
|
|
initialized = true
|
2022-12-15 14:09:44 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
await makeScrollable()
|
|
|
|
} catch (error) {
|
|
|
|
logger.error(error)
|
|
|
|
useMessageToaster().toastError('Failed to load artists.')
|
|
|
|
initialized = false
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
</script>
|