koel/resources/assets/js/components/artist/card.vue

85 lines
2.6 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<article
:title="artist.name"
@dragstart="dragStart"
class="item"
:class="layout"
draggable="true"
tabindex="0"
data-test="artist-card"
v-if="showing"
2022-04-15 17:00:08 +00:00
@contextmenu.prevent.stop="requestContextMenu"
2022-04-15 14:24:30 +00:00
@dblclick="shuffle"
>
<span class="thumbnail-wrapper">
2022-04-15 17:00:08 +00:00
<ArtistThumbnail :entity="artist"/>
2022-04-15 14:24:30 +00:00
</span>
<footer>
<div class="info">
<a class="name" :href="`#!/artist/${artist.id}`">
{{ artist.name }}
</a>
</div>
<p class="meta">
<span class="left">
2022-04-15 17:00:08 +00:00
{{ pluralize(artist.albums.length, 'album') }}
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
{{ pluralize(artist.songs.length, 'song') }}
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
{{ pluralize(artist.playCount, 'play') }}
2022-04-15 14:24:30 +00:00
</span>
<span class="right">
<a
:title="`Shuffle all songs by ${artist.name}`"
@click.prevent="shuffle"
class="shuffle-artist"
href
role="button"
>
<i class="fa fa-random"></i>
</a>
<a
:title="`Download all songs by ${artist.name}`"
@click.prevent="download"
class="download-artist"
href
role="button"
v-if="sharedState.allowDownload"
>
<i class="fa fa-download"></i>
</a>
</span>
</p>
</footer>
</article>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
import { computed, defineAsyncComponent, reactive, toRefs } from 'vue'
import { eventBus, pluralize, startDragging } from '@/utils'
2022-04-15 14:24:30 +00:00
import { artistStore, sharedStore } from '@/stores'
2022-04-15 17:00:08 +00:00
import { download as downloadService, playback } from '@/services'
import { useArtistAttributes } from '@/composables'
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const ArtistThumbnail = defineAsyncComponent(() => import('@/components/ui/album-artist-thumbnail.vue'))
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const props = withDefaults(defineProps<{ artist: Artist, layout: ArtistAlbumCardLayout }>(), { layout: 'full' })
const { artist, layout } = toRefs(props)
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const { length, fmtLength, image } = useArtistAttributes(artist.value)
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const sharedState = reactive(sharedStore.state)
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const showing = computed(() => artist.value.songs.length && !artistStore.isVariousArtists(artist.value))
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const shuffle = () => playback.playAllByArtist(artist.value, true /* shuffled */)
const download = () => downloadService.fromArtist(artist.value)
const dragStart = (event: DragEvent) => startDragging(event, artist.value, 'Artist')
const requestContextMenu = (event: MouseEvent) => eventBus.emit('ARTIST_CONTEXT_MENU_REQUESTED', event, artist.value)
2022-04-15 14:24:30 +00:00
</script>
<style lang="scss">
@include artist-album-card();
</style>