2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
|
|
|
<section id="albumsWrapper">
|
2022-07-16 15:44:45 +00:00
|
|
|
<ScreenHeader layout="collapsed">
|
2022-04-15 14:24:30 +00:00
|
|
|
Albums
|
|
|
|
<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="albums main-scroll-wrap"
|
|
|
|
data-testid="album-list"
|
|
|
|
@scroll="scrolling"
|
|
|
|
>
|
2022-06-10 10:47:46 +00:00
|
|
|
<AlbumCard v-for="album in albums" :key="album.id" :album="album" :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>
|
2022-07-07 18:05:46 +00:00
|
|
|
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 { albumStore, 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-07-07 18:05:46 +00:00
|
|
|
import AlbumCard from '@/components/album/AlbumCard.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')
|
2022-05-16 07:34:18 +00:00
|
|
|
const albums = toRef(albumStore.state, 'albums')
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const {
|
|
|
|
ToTopButton,
|
|
|
|
scroller,
|
|
|
|
scrolling,
|
|
|
|
makeScrollable
|
2022-06-10 10:47:46 +00:00
|
|
|
} = useInfiniteScroll(async () => await fetchAlbums())
|
2022-04-15 14:24:30 +00:00
|
|
|
|
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-06-10 10:47:46 +00:00
|
|
|
watch(viewMode, () => (preferences.albumsViewMode = 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 moreAlbumsAvailable = computed(() => page.value !== null)
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
const fetchAlbums = async () => {
|
|
|
|
if (loading || !moreAlbumsAvailable.value) return
|
|
|
|
|
|
|
|
loading = true
|
|
|
|
page.value = await albumStore.fetch(page.value!)
|
|
|
|
loading = false
|
|
|
|
}
|
|
|
|
|
|
|
|
eventBus.on('LOAD_MAIN_CONTENT', async (view: MainViewName) => {
|
|
|
|
if (view === 'Albums' && !initialized) {
|
2022-07-11 17:30:51 +00:00
|
|
|
viewMode.value = preferences.albumsViewMode || '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">
|
|
|
|
#albumsWrapper {
|
|
|
|
.albums {
|
|
|
|
@include artist-album-wrapper();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|
2022-07-04 15:57:08 +00:00
|
|
|
`
|