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

55 lines
1.9 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<ContextMenuBase ref="base" data-testid="artist-context-menu" extra-class="artist-menu">
2022-04-15 14:24:30 +00:00
<template v-if="artist">
<li data-testid="play" @click="play">Play All</li>
<li data-testid="shuffle" @click="shuffle">Shuffle All</li>
2022-04-15 14:24:30 +00:00
<template v-if="isStandardArtist">
<li class="separator"></li>
<li data-testid="view-artist" @click="viewArtistDetails">Go to Artist</li>
2022-04-15 14:24:30 +00:00
</template>
<template v-if="isStandardArtist && allowDownload">
2022-04-15 14:24:30 +00:00
<li class="separator"></li>
<li data-testid="download" @click="download">Download</li>
2022-04-15 14:24:30 +00:00
</template>
</template>
2022-04-24 08:29:14 +00:00
</ContextMenuBase>
2022-04-15 14:24:30 +00:00
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
import { computed, ref, toRef } from 'vue'
2022-06-10 10:47:46 +00:00
import { artistStore, commonStore, songStore } from '@/stores'
2022-04-24 08:50:45 +00:00
import { downloadService, playbackService } from '@/services'
2022-04-15 17:00:08 +00:00
import { useContextMenu } from '@/composables'
import { RouterKey } from '@/symbols'
import { eventBus, requireInjection } from '@/utils'
2022-04-15 14:24:30 +00:00
2022-06-10 10:47:46 +00:00
const { context, base, ContextMenuBase, open, trigger } = useContextMenu()
const router = requireInjection(RouterKey)
2022-04-15 14:24:30 +00:00
const artist = ref<Artist>()
2022-06-10 10:47:46 +00:00
const allowDownload = toRef(commonStore.state, 'allow_download')
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const isStandardArtist = computed(() =>
!artistStore.isUnknown(artist.value!)
&& !artistStore.isVarious(artist.value!)
2022-04-15 17:00:08 +00:00
)
2022-04-15 14:24:30 +00:00
const play = () => trigger(async () => {
await playbackService.queueAndPlay(await songStore.fetchForArtist(artist.value!))
router.go('queue')
})
2022-04-15 14:24:30 +00:00
const shuffle = () => trigger(async () => {
await playbackService.queueAndPlay(await songStore.fetchForArtist(artist.value!), true)
router.go('queue')
})
2022-04-15 14:24:30 +00:00
const viewArtistDetails = () => trigger(() => router.go(`artist/${artist.value!.id}`))
const download = () => trigger(() => downloadService.fromArtist(artist.value!))
2022-04-15 14:24:30 +00:00
eventBus.on('ARTIST_CONTEXT_MENU_REQUESTED', async (e: MouseEvent, _artist: Artist) => {
artist.value = _artist
await open(e.pageY, e.pageX, { _artist })
})
2022-04-15 14:24:30 +00:00
</script>