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

54 lines
1.9 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
2024-04-29 19:50:03 +00:00
<BaseCard
2022-04-21 21:51:17 +00:00
v-if="showing"
:entity="artist"
:layout="layout"
2022-04-15 14:24:30 +00:00
:title="artist.name"
@contextmenu="requestContextMenu"
2022-04-15 14:24:30 +00:00
@dblclick="shuffle"
@dragstart="onDragStart"
2022-04-15 14:24:30 +00:00
>
<template #name>
2024-04-04 22:20:42 +00:00
<a :href="`#/artist/${artist.id}`" class="font-medium" data-testid="name">{{ artist.name }}</a>
</template>
<template #meta>
2024-04-04 22:20:42 +00:00
<a :title="`Shuffle all songs by ${artist.name}`" role="button" @click.prevent="shuffle">
Shuffle
</a>
2024-04-04 22:20:42 +00:00
<a v-if="allowDownload" :title="`Download all songs by ${artist.name}`" role="button" @click.prevent="download">
Download
</a>
</template>
2024-04-29 19:50:03 +00:00
</BaseCard>
2022-04-15 14:24:30 +00:00
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
import { computed, toRef, toRefs } from 'vue'
2022-11-18 18:44:20 +00:00
import { eventBus } from '@/utils'
2022-05-04 20:47:12 +00:00
import { artistStore, commonStore, songStore } from '@/stores'
2022-04-24 08:50:45 +00:00
import { downloadService, playbackService } from '@/services'
2022-11-18 18:44:20 +00:00
import { useDraggable, useRouter } from '@/composables'
2024-04-29 19:50:03 +00:00
import BaseCard from '@/components/ui/album-artist/AlbumOrArtistCard.vue'
2022-04-15 14:24:30 +00:00
const props = withDefaults(defineProps<{ artist: Artist, layout?: ArtistAlbumCardLayout }>(), { layout: 'full' })
2022-11-18 18:44:20 +00:00
const { go } = useRouter()
const { startDragging } = useDraggable('artist')
2022-04-15 17:00:08 +00:00
const { artist, layout } = toRefs(props)
2022-04-15 14:24:30 +00:00
// We're not checking for supports_batch_downloading here, as the number of songs by the artist is not yet known.
2024-01-04 11:35:36 +00:00
const allowDownload = toRef(commonStore.state, 'allows_download')
2022-06-10 10:47:46 +00:00
const showing = computed(() => artistStore.isStandard(artist.value))
2022-04-15 14:24:30 +00:00
2022-06-10 10:47:46 +00:00
const shuffle = async () => {
2022-10-21 20:06:43 +00:00
playbackService.queueAndPlay(await songStore.fetchForArtist(artist.value), true /* shuffled */)
2022-11-18 18:44:20 +00:00
go('queue')
2022-06-10 10:47:46 +00:00
}
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const download = () => downloadService.fromArtist(artist.value)
const onDragStart = (event: DragEvent) => startDragging(event, artist.value)
2022-04-15 17:00:08 +00:00
const requestContextMenu = (event: MouseEvent) => eventBus.emit('ARTIST_CONTEXT_MENU_REQUESTED', event, artist.value)
2022-04-15 14:24:30 +00:00
</script>