koel/resources/assets/js/composables/useSongMenuMethods.ts

23 lines
950 B
TypeScript
Raw Normal View History

2022-07-04 10:39:02 +00:00
import { Ref } from 'vue'
import { favoriteStore, queueStore } from '@/stores'
import { usePlaylistManagement } from '@/composables'
import { eventBus } from '@/utils'
2022-04-15 14:24:30 +00:00
export const useSongMenuMethods = (songs: Ref<Song[]>, close: Closure) => {
const { addSongsToPlaylist } = usePlaylistManagement()
2024-04-29 20:35:55 +00:00
const trigger = async (cb: Closure) => {
2022-04-15 14:24:30 +00:00
close()
2024-04-29 20:35:55 +00:00
await cb()
}
2022-04-15 14:24:30 +00:00
return {
2024-04-29 20:35:55 +00:00
queueSongsAfterCurrent: () => trigger(() => queueStore.queueAfterCurrent(songs.value)),
queueSongsToBottom: () => trigger(() => queueStore.queue(songs.value)),
queueSongsToTop: () => trigger(() => queueStore.queueToTop(songs.value)),
addSongsToFavorites: () => trigger(() => favoriteStore.like(songs.value)),
addSongsToExistingPlaylist: (playlist: Playlist) => trigger(() => addSongsToPlaylist(playlist, songs.value)),
addSongsToNewPlaylist: () => trigger(() => eventBus.emit('MODAL_SHOW_CREATE_PLAYLIST_FORM', null, songs.value))
2022-04-15 14:24:30 +00:00
}
}