2022-10-21 20:06:43 +00:00
|
|
|
<template>
|
|
|
|
<section id="genreWrapper">
|
|
|
|
<ScreenHeader :layout="headerLayout" v-if="genre">
|
2022-10-24 12:48:30 +00:00
|
|
|
Genre: <span class="text-thin">{{ decodeURIComponent(name) }}</span>
|
2022-10-21 20:06:43 +00:00
|
|
|
<ControlsToggle v-if="songs.length" v-model="showingControls"/>
|
|
|
|
|
|
|
|
<template v-slot:thumbnail>
|
|
|
|
<ThumbnailStack :thumbnails="thumbnails"/>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template v-if="genre" v-slot:meta>
|
|
|
|
<span>{{ pluralize(genre.song_count, 'song') }}</span>
|
|
|
|
<span>{{ duration }}</span>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template v-slot:controls>
|
|
|
|
<SongListControls v-if="!isPhone || showingControls" @playAll="playAll" @playSelected="playSelected"/>
|
|
|
|
</template>
|
|
|
|
</ScreenHeader>
|
|
|
|
<ScreenHeaderSkeleton v-else/>
|
|
|
|
|
|
|
|
<SongListSkeleton v-if="showSkeletons"/>
|
|
|
|
<SongList
|
|
|
|
v-else
|
|
|
|
ref="songList"
|
|
|
|
@sort="sort"
|
|
|
|
@press:enter="onPressEnter"
|
|
|
|
@scroll-breakpoint="onScrollBreakpoint"
|
|
|
|
@scrolled-to-end="fetch"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<ScreenEmptyState v-if="!songs.length && !loading">
|
|
|
|
<template v-slot:icon>
|
|
|
|
<icon :icon="faTags"/>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
No songs in this genre.
|
|
|
|
</ScreenEmptyState>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed, onMounted, ref, watch } from 'vue'
|
|
|
|
import { faTags } from '@fortawesome/free-solid-svg-icons'
|
2022-11-18 18:44:20 +00:00
|
|
|
import { eventBus, logger, pluralize, secondsToHumanReadable } from '@/utils'
|
2022-11-18 17:45:38 +00:00
|
|
|
import { playbackService } from '@/services'
|
2022-10-21 20:06:43 +00:00
|
|
|
import { genreStore, songStore } from '@/stores'
|
2022-11-18 18:44:20 +00:00
|
|
|
import { useDialogBox, useRouter, useSongList } from '@/composables'
|
2022-10-21 20:06:43 +00:00
|
|
|
|
|
|
|
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
|
|
|
|
import ScreenEmptyState from '@/components/ui/ScreenEmptyState.vue'
|
|
|
|
import SongListSkeleton from '@/components/ui/skeletons/SongListSkeleton.vue'
|
|
|
|
import ScreenHeaderSkeleton from '@/components/ui/skeletons/ScreenHeaderSkeleton.vue'
|
|
|
|
|
|
|
|
const {
|
|
|
|
SongList,
|
|
|
|
SongListControls,
|
|
|
|
ControlsToggle,
|
|
|
|
ThumbnailStack,
|
|
|
|
headerLayout,
|
|
|
|
songs,
|
|
|
|
songList,
|
|
|
|
thumbnails,
|
|
|
|
showingControls,
|
|
|
|
isPhone,
|
|
|
|
onPressEnter,
|
|
|
|
playSelected,
|
|
|
|
onScrollBreakpoint
|
2022-11-12 21:38:31 +00:00
|
|
|
} = useSongList(ref<Song[]>([]))
|
2022-10-21 20:06:43 +00:00
|
|
|
|
2022-11-18 17:45:38 +00:00
|
|
|
const { showErrorDialog } = useDialogBox()
|
2022-11-18 18:44:20 +00:00
|
|
|
const { getRouteParam, go, onRouteChanged } = useRouter()
|
2022-10-21 20:06:43 +00:00
|
|
|
|
|
|
|
let sortField: SongListSortField = 'title'
|
|
|
|
let sortOrder: SortOrder = 'asc'
|
|
|
|
|
|
|
|
const randomSongCount = 500
|
|
|
|
const name = ref<string | null>(null)
|
|
|
|
const genre = ref<Genre | null>(null)
|
|
|
|
const loading = ref(false)
|
|
|
|
const page = ref<number | null>(1)
|
|
|
|
|
|
|
|
const moreSongsAvailable = computed(() => page.value !== null)
|
|
|
|
const showSkeletons = computed(() => loading.value && songs.value.length === 0)
|
2022-10-28 13:56:06 +00:00
|
|
|
const duration = computed(() => secondsToHumanReadable(genre.value?.length ?? 0))
|
2022-10-21 20:06:43 +00:00
|
|
|
|
|
|
|
const sort = async (field: SongListSortField, order: SortOrder) => {
|
|
|
|
page.value = 1
|
|
|
|
songs.value = []
|
|
|
|
sortField = field
|
|
|
|
sortOrder = order
|
|
|
|
|
|
|
|
await fetch()
|
|
|
|
}
|
|
|
|
|
|
|
|
const fetch = async () => {
|
|
|
|
if (!moreSongsAvailable.value || loading.value) return
|
|
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
|
|
try {
|
|
|
|
let fetched
|
|
|
|
|
|
|
|
[genre.value, fetched] = await Promise.all([
|
|
|
|
genreStore.fetchOne(name.value!),
|
|
|
|
songStore.paginateForGenre(name.value!, sortField, sortOrder, page.value!)
|
|
|
|
])
|
|
|
|
|
|
|
|
page.value = fetched.nextPage
|
|
|
|
songs.value.push(...fetched.songs)
|
|
|
|
} catch (e) {
|
2022-11-19 22:12:38 +00:00
|
|
|
showErrorDialog('Failed to fetch genre details or genre was not found.', 'Error')
|
2022-10-21 20:06:43 +00:00
|
|
|
logger.error(e)
|
|
|
|
} finally {
|
|
|
|
loading.value = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const refresh = async () => {
|
|
|
|
genre.value = null
|
|
|
|
page.value = 1
|
|
|
|
songs.value = []
|
|
|
|
|
|
|
|
await fetch()
|
|
|
|
}
|
|
|
|
|
2022-11-18 18:44:20 +00:00
|
|
|
const getNameFromRoute = () => getRouteParam('name') ?? null
|
2022-10-21 20:06:43 +00:00
|
|
|
|
2022-11-18 18:44:20 +00:00
|
|
|
onRouteChanged(route => {
|
2022-10-21 20:06:43 +00:00
|
|
|
if (route.screen !== 'Genre') return
|
|
|
|
name.value = getNameFromRoute()
|
|
|
|
})
|
|
|
|
|
|
|
|
const playAll = async () => {
|
|
|
|
if (!genre.value) return
|
|
|
|
|
|
|
|
// we ignore the queueAndPlay's await to avoid blocking the UI
|
|
|
|
if (genre.value!.song_count <= randomSongCount) {
|
|
|
|
playbackService.queueAndPlay(songs.value, true)
|
|
|
|
} else {
|
|
|
|
playbackService.queueAndPlay(await songStore.fetchRandomForGenre(genre.value!, randomSongCount))
|
|
|
|
}
|
|
|
|
|
2022-11-18 18:44:20 +00:00
|
|
|
go('queue')
|
2022-10-21 20:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(() => (name.value = getNameFromRoute()))
|
|
|
|
|
|
|
|
watch(name, async () => name.value && await refresh())
|
|
|
|
|
|
|
|
// We can't really tell how/if the genres have been updated, so we just refresh the list
|
2022-10-25 17:38:52 +00:00
|
|
|
eventBus.on('SONGS_UPDATED', async () => genre.value && await refresh())
|
2022-10-21 20:06:43 +00:00
|
|
|
</script>
|