2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
2024-04-04 22:20:42 +00:00
|
|
|
<ScreenBase>
|
|
|
|
<template #header>
|
|
|
|
<ScreenHeader layout="collapsed">
|
|
|
|
Albums
|
|
|
|
<template #controls>
|
|
|
|
<ViewModeSwitch v-model="viewMode" />
|
|
|
|
</template>
|
|
|
|
</ScreenHeader>
|
|
|
|
</template>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2023-12-28 22:32:58 +00:00
|
|
|
<ScreenEmptyState v-if="libraryEmpty">
|
|
|
|
<template #icon>
|
|
|
|
<Icon :icon="faCompactDisc" />
|
|
|
|
</template>
|
|
|
|
No albums 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">
|
|
|
|
<AlbumGrid :view-mode="viewMode" data-testid="album-grid">
|
|
|
|
<template v-if="showSkeletons">
|
|
|
|
<AlbumCardSkeleton v-for="i in 10" :key="i" :layout="itemLayout" />
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<AlbumCard v-for="album in albums" :key="album.id" :album="album" :layout="itemLayout" />
|
|
|
|
<ToTopButton />
|
|
|
|
</template>
|
|
|
|
</AlbumGrid>
|
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>
|
2023-12-28 22:32:58 +00:00
|
|
|
import { faCompactDisc } 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 { albumStore, commonStore, preferenceStore as preferences } from '@/stores'
|
2024-04-23 11:24:29 +00:00
|
|
|
import { useAuthorization, useErrorHandler, useInfiniteScroll, useRouter } 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'
|
2022-07-30 15:08:20 +00:00
|
|
|
import AlbumCardSkeleton 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'
|
2024-04-04 22:20:42 +00:00
|
|
|
import ScreenBase from '@/components/screens/ScreenBase.vue'
|
|
|
|
import AlbumGrid from '@/components/ui/album-artist/AlbumOrArtistGrid.vue'
|
2023-12-28 22:32:58 +00:00
|
|
|
|
|
|
|
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')
|
2022-05-16 07:34:18 +00:00
|
|
|
const albums = toRef(albumStore.state, 'albums')
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2024-04-23 11:24:29 +00:00
|
|
|
const { ToTopButton, makeScrollable } = useInfiniteScroll(gridContainer, async () => await fetchAlbums())
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2024-01-23 22:50:50 +00:00
|
|
|
watch(viewMode, () => (preferences.albums_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 moreAlbumsAvailable = computed(() => page.value !== null)
|
2022-07-30 15:08:20 +00:00
|
|
|
const showSkeletons = computed(() => loading.value && albums.value.length === 0)
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
const fetchAlbums = async () => {
|
2022-07-30 15:08:20 +00:00
|
|
|
if (loading.value || !moreAlbumsAvailable.value) return
|
2022-06-10 10:47:46 +00:00
|
|
|
|
2022-07-30 15:08:20 +00:00
|
|
|
loading.value = true
|
2022-07-22 21:56:13 +00:00
|
|
|
page.value = await albumStore.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('Albums', 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.albums_view_mode || 'thumbnails'
|
2022-06-10 10:47:46 +00:00
|
|
|
initialized = true
|
2022-12-15 14:09:44 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
await makeScrollable()
|
2024-04-23 11:24:29 +00:00
|
|
|
} catch (error: unknown) {
|
2022-12-15 14:09:44 +00:00
|
|
|
initialized = false
|
2024-04-23 11:24:29 +00:00
|
|
|
useErrorHandler().handleHttpError(error)
|
2022-12-15 14:09:44 +00:00
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
</script>
|