koel/resources/assets/js/components/playlist/PlaylistFolderContextMenu.vue

53 lines
1.9 KiB
Vue
Raw Normal View History

<template>
<ContextMenuBase ref="base">
<template v-if="folder">
<template v-if="playable">
<li @click="play">Play All</li>
<li @click="shuffle">Shuffle All</li>
2022-12-02 16:17:37 +00:00
<li class="separator" />
</template>
<li @click="createPlaylist">New Playlist</li>
<li @click="createSmartPlaylist">New Smart Playlist</li>
2022-12-02 16:17:37 +00:00
<li class="separator" />
<li @click="rename">Rename</li>
<li @click="destroy">Delete</li>
</template>
</ContextMenuBase>
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue'
2022-11-18 18:44:20 +00:00
import { eventBus } from '@/utils'
import { playlistStore, songStore } from '@/stores'
import { playbackService } from '@/services'
2022-11-18 18:44:20 +00:00
import { useContextMenu, useRouter } from '@/composables'
2022-11-18 18:44:20 +00:00
const { go } = useRouter()
2022-12-02 16:17:37 +00:00
const { base, ContextMenuBase, open, trigger } = useContextMenu()
const folder = ref<PlaylistFolder>()
const playlistsInFolder = computed(() => folder.value ? playlistStore.byFolder(folder.value) : [])
const playable = computed(() => playlistsInFolder.value.length > 0)
const play = () => trigger(async () => {
2022-10-21 20:06:43 +00:00
playbackService.queueAndPlay(await songStore.fetchForPlaylistFolder(folder.value!))
2022-11-18 18:44:20 +00:00
go('queue')
})
const shuffle = () => trigger(async () => {
2022-10-21 20:06:43 +00:00
playbackService.queueAndPlay(await songStore.fetchForPlaylistFolder(folder.value!), true)
2022-11-18 18:44:20 +00:00
go('queue')
})
2022-12-02 16:17:37 +00:00
const createPlaylist = () => trigger(() => eventBus.emit('MODAL_SHOW_CREATE_PLAYLIST_FORM', folder.value!))
const createSmartPlaylist = () => trigger(() => eventBus.emit('MODAL_SHOW_CREATE_SMART_PLAYLIST_FORM', folder.value!))
const rename = () => trigger(() => eventBus.emit('MODAL_SHOW_EDIT_PLAYLIST_FOLDER_FORM', folder.value!))
const destroy = () => trigger(() => eventBus.emit('PLAYLIST_FOLDER_DELETE', folder.value!))
eventBus.on('PLAYLIST_FOLDER_CONTEXT_MENU_REQUESTED', async (e, _folder) => {
folder.value = _folder
2022-12-02 16:17:37 +00:00
await open(e.pageY, e.pageX)
})
</script>