koel/resources/assets/js/components/album/context-menu.vue

57 lines
1.8 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
2022-04-15 17:00:08 +00:00
<BaseContextMenu extra-class="album-menu" data-testid="album-context-menu" ref="base">
2022-04-15 14:24:30 +00:00
<template v-if="album">
<li data-test="play" @click="play">Play All</li>
<li data-test="shuffle" @click="shuffle">Shuffle All</li>
<li class="separator"></li>
<li data-test="view-album" @click="viewAlbumDetails" v-if="isStandardAlbum">Go to Album</li>
<li data-test="view-artist" @click="viewArtistDetails" v-if="isStandardArtist">Go to Artist</li>
<template v-if="isStandardAlbum && sharedState.allowDownload">
<li class="separator"></li>
2022-04-15 17:00:08 +00:00
<li data-test="download" @click="download">Download</li>
2022-04-15 14:24:30 +00:00
</template>
</template>
2022-04-15 17:00:08 +00:00
</BaseContextMenu>
2022-04-15 14:24:30 +00:00
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
import { computed, reactive, toRefs } from 'vue'
2022-04-15 14:24:30 +00:00
import { albumStore, artistStore, sharedStore } from '@/stores'
2022-04-15 17:00:08 +00:00
import { download as downloadService, playback } from '@/services'
import { useContextMenu } from '@/composables'
2022-04-15 14:24:30 +00:00
import router from '@/router'
2022-04-15 17:00:08 +00:00
const { base, BaseContextMenu, open, close } = useContextMenu()
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const props = defineProps<{ album: Album }>()
const { album } = toRefs(props)
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 isStandardAlbum = computed(() => !albumStore.isUnknownAlbum(album.value))
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const isStandardArtist = computed(() => {
return !artistStore.isUnknownArtist(album.value.artist) && !artistStore.isVariousArtists(album.value.artist)
})
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const play = () => playback.playAllInAlbum(album.value)
const shuffle = () => playback.playAllInAlbum(album.value, true /* shuffled */)
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const viewAlbumDetails = () => {
router.go(`album/${album.value.id}`)
close()
}
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const viewArtistDetails = () => {
router.go(`artist/${album.value.artist.id}`)
close()
}
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const download = () => {
downloadService.fromAlbum(album.value)
close()
}
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
defineExpose({ open, close })
2022-04-15 14:24:30 +00:00
</script>