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

65 lines
1.9 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<section id="artistsWrapper">
2022-04-15 17:00:08 +00:00
<ScreenHeader>
2022-04-15 14:24:30 +00:00
Artists
<template v-slot:controls>
2022-04-19 21:48:56 +00:00
<ViewModeSwitch v-model="viewMode" :value="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-04-21 21:51:17 +00:00
<div ref="scroller" :class="`as-${viewMode}`" class="artists main-scroll-wrap" @scroll="scrolling">
<ArtistCard v-for="item in displayedItems" :key="item.id" :artist="item" :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, defineAsyncComponent, nextTick, ref, watch } from 'vue'
import { eventBus, limitBy } 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
2022-04-15 17:00:08 +00:00
const {
ToTopButton,
displayedItemCount,
scroller,
scrolling,
makeScrollable
} = useInfiniteScroll(9)
2022-04-15 14:24:30 +00:00
2022-04-21 16:06:45 +00:00
const ScreenHeader = defineAsyncComponent(() => import('@/components/ui/ScreenHeader.vue'))
2022-04-21 21:51:17 +00:00
const ArtistCard = defineAsyncComponent(() => import('@/components/artist/ArtistCard.vue'))
2022-04-15 17:00:08 +00:00
const ViewModeSwitch = defineAsyncComponent(() => import('@/components/ui/view-mode-switch.vue'))
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const viewMode = ref<ArtistAlbumViewMode>('thumbnails')
const artists = ref<Artist[]>([])
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const displayedItems = computed(() => limitBy(artists.value, displayedItemCount.value))
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-04-15 17:00:08 +00:00
eventBus.on({
KOEL_READY () {
artists.value = artistStore.all
viewMode.value = preferences.artistsViewMode || 'thumbnails'
},
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
async LOAD_MAIN_CONTENT (view: MainViewName) {
if (view === 'Artists') {
await nextTick()
makeScrollable(artists.value.length)
}
2022-04-15 14:24:30 +00:00
}
})
</script>
<style lang="scss">
#artistsWrapper {
.artists {
@include artist-album-wrapper();
}
}
</style>