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

76 lines
2 KiB
Vue
Raw Normal View History

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
<template v-slot:controls>
2022-05-29 21:36:45 +00:00
<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
2022-07-11 17:30:51 +00:00
<div
ref="scroller"
:class="`as-${viewMode}`"
class="artists main-scroll-wrap"
data-testid="artist-list"
@scroll="scrolling"
>
2022-06-10 10:47:46 +00:00
<ArtistCard v-for="artist in artists" :key="artist.id" :artist="artist" :layout="itemLayout"/>
2022-04-15 17:00:08 +00:00
<ToTopButton/>
2022-04-15 14:24:30 +00:00
</div>
</section>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
import { computed, ref, toRef, watch } from 'vue'
2022-06-10 10:47:46 +00:00
import { eventBus } from '@/utils'
2022-04-15 14:24:30 +00:00
import { artistStore, preferenceStore as preferences } from '@/stores'
2022-04-15 17:00:08 +00:00
import { useInfiniteScroll } from '@/composables'
2022-04-15 14:24:30 +00:00
import ArtistCard from '@/components/artist/ArtistCard.vue'
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
import ViewModeSwitch from '@/components/ui/ViewModeSwitch.vue'
2022-04-15 14:24:30 +00:00
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,
scroller,
scrolling,
makeScrollable
} = useInfiniteScroll(async () => await fetchArtists())
2022-04-15 17:00:08 +00:00
const itemLayout = computed<ArtistAlbumCardLayout>(() => viewMode.value === 'thumbnails' ? 'full' : 'compact')
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
watch(viewMode, () => preferences.artistsViewMode = viewMode.value)
2022-04-15 14:24:30 +00:00
2022-06-10 10:47:46 +00:00
let initialized = false
let loading = false
const page = ref<number | null>(1)
const moreArtistsAvailable = computed(() => page.value !== null)
const fetchArtists = async () => {
if (loading || !moreArtistsAvailable.value) return
loading = true
2022-07-22 22:03:25 +00:00
page.value = await artistStore.paginate(page.value!)
2022-06-10 10:47:46 +00:00
loading = false
}
eventBus.on('LOAD_MAIN_CONTENT', async (view: MainViewName) => {
if (view === 'Artists' && !initialized) {
2022-07-11 17:30:51 +00:00
viewMode.value = preferences.artistsViewMode || 'thumbnails'
2022-06-10 10:47:46 +00:00
await makeScrollable()
initialized = true
2022-04-15 14:24:30 +00:00
}
})
</script>
<style lang="scss">
#artistsWrapper {
.artists {
@include artist-album-wrapper();
}
}
</style>