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

127 lines
3.3 KiB
Vue
Raw Normal View History

2022-10-21 20:06:43 +00:00
<template>
2024-04-04 22:20:42 +00:00
<ScreenBase>
<template #header>
<ScreenHeader layout="collapsed">Genres</ScreenHeader>
</template>
<ScreenEmptyState v-if="libraryEmpty">
<template #icon>
<Icon :icon="faTags" />
</template>
No genres 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
<ul v-if="genres" class="genres text-center">
<li
v-for="genre in genres"
:key="genre.name"
:class="`level-${getLevel(genre)}`"
class="rounded-[0.5em] inline-block m-1.5 align-middle overflow-hidden"
>
<a
:href="`/#/genres/${encodeURIComponent(genre.name)}`"
:title="`${genre.name}: ${pluralize(genre.song_count, 'song')}`"
2024-04-23 21:01:27 +00:00
class="bg-white/15 inline-flex items-center justify-center !text-k-text-secondary
transition-colors duration-200 ease-in-out hover:!text-k-text-primary hover:bg-k-highlight"
2024-04-04 22:20:42 +00:00
>
<span class="name bg-white/5 px-[0.5em] py-[0.2em] leading-normal">{{ genre.name }}</span>
<span class="count items-center px-[0.5em] py-[0.2em]">
{{ genre.song_count }}
</span>
</a>
</li>
</ul>
<ul v-else class="text-center">
<li v-for="i in 20" :key="i" class="inline-block">
2024-04-04 22:20:42 +00:00
<GenreItemSkeleton />
</li>
</ul>
</ScreenBase>
2022-10-21 20:06:43 +00:00
</template>
<script lang="ts" setup>
import { faTags } from '@fortawesome/free-solid-svg-icons'
2022-10-21 20:06:43 +00:00
import { maxBy, minBy } from 'lodash'
import { computed, onMounted, ref } from 'vue'
import { commonStore, genreStore } from '@/stores'
2022-10-21 20:06:43 +00:00
import { pluralize } from '@/utils'
import { useAuthorization } from '@/composables'
2022-10-21 20:06:43 +00:00
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
import GenreItemSkeleton from '@/components/ui/skeletons/GenreItemSkeleton.vue'
import ScreenEmptyState from '@/components/ui/ScreenEmptyState.vue'
2024-04-04 22:20:42 +00:00
import ScreenBase from '@/components/screens/ScreenBase.vue'
const { isAdmin } = useAuthorization()
2022-10-21 20:06:43 +00:00
const genres = ref<Genre[]>()
const libraryEmpty = computed(() => commonStore.state.song_length === 0)
2022-10-21 20:06:43 +00:00
const mostPopular = computed(() => maxBy(genres.value, 'song_count'))
const leastPopular = computed(() => minBy(genres.value, 'song_count'))
const levels = computed(() => {
const max = mostPopular.value?.song_count || 1
const min = leastPopular.value?.song_count || 1
const range = max - min
const step = range / 5
return [min, min + step, min + step * 2, min + step * 3, min + step * 4, max]
})
const getLevel = (genre: Genre) => {
const index = levels.value.findIndex((level) => genre.song_count <= level)
return index === -1 ? 5 : index
}
onMounted(async () => {
if (libraryEmpty.value) return
genres.value = await genreStore.fetchAll()
})
2022-10-21 20:06:43 +00:00
</script>
2024-04-04 20:13:35 +00:00
<style lang="postcss" scoped>
2022-10-21 20:06:43 +00:00
.genres {
li {
font-size: var(--unit);
2024-04-04 22:20:42 +00:00
&:active {
@apply scale-95;
2022-10-21 20:06:43 +00:00
}
}
2024-04-04 20:13:35 +00:00
.level-0 {
--unit: 1rem;
2024-04-04 22:20:42 +00:00
@apply opacity-80;
2024-04-04 20:13:35 +00:00
}
.level-1 {
--unit: 1.4rem;
2024-04-04 22:20:42 +00:00
@apply opacity-[84%];
2024-04-04 20:13:35 +00:00
}
.level-2 {
--unit: 1.8rem;
2024-04-04 22:20:42 +00:00
@apply opacity-[88%];
2024-04-04 20:13:35 +00:00
}
.level-3 {
--unit: 2.2rem;
2024-04-04 22:20:42 +00:00
@apply opacity-[92%];
2024-04-04 20:13:35 +00:00
}
.level-4 {
--unit: 2.6rem;
2024-04-04 22:20:42 +00:00
@apply opacity-[96%];
2024-04-04 20:13:35 +00:00
}
.level-5 {
--unit: 3rem;
2024-04-04 22:20:42 +00:00
@apply opacity-100;
2022-10-21 20:06:43 +00:00
}
}
</style>