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

43 lines
979 B
TypeScript
Raw Normal View History

2022-04-15 14:24:30 +00:00
import { favoriteStore, playlistStore, queueStore } from '@/stores'
/**
* Includes the methods trigger-able on a song (context) menu.
* Each component including this mixin must have a `songs` array as either data, prop, or computed.
*/
2022-04-15 17:00:08 +00:00
export const useSongMenuMethods = (songs: Song[], close: TAnyFunction) => {
2022-04-20 09:37:22 +00:00
console.log(songs)
2022-04-15 14:24:30 +00:00
const queueSongsAfterCurrent = () => {
2022-04-15 17:00:08 +00:00
queueStore.queueAfterCurrent(songs)
2022-04-15 14:24:30 +00:00
close()
}
const queueSongsToBottom = () => {
2022-04-15 17:00:08 +00:00
queueStore.queue(songs)
2022-04-15 14:24:30 +00:00
close()
}
const queueSongsToTop = () => {
2022-04-15 17:00:08 +00:00
queueStore.queueToTop(songs)
2022-04-15 14:24:30 +00:00
close()
}
const addSongsToFavorite = async () => {
2022-04-15 17:00:08 +00:00
await favoriteStore.like(songs)
2022-04-15 14:24:30 +00:00
close()
}
const addSongsToExistingPlaylist = async (playlist: Playlist) => {
2022-04-15 17:00:08 +00:00
await playlistStore.addSongs(playlist, songs)
2022-04-15 14:24:30 +00:00
close()
}
return {
queueSongsAfterCurrent,
queueSongsToBottom,
queueSongsToTop,
addSongsToFavorite,
addSongsToExistingPlaylist
}
}