mirror of
https://github.com/koel/koel
synced 2024-12-20 17:43:36 +00:00
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { Ref } from 'vue'
|
|
import { favoriteStore, playlistStore, queueStore } from '@/stores'
|
|
import { alerts, pluralize } from '@/utils'
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
export const useSongMenuMethods = (songs: Ref<Song[]>, close: Closure) => {
|
|
const queueSongsAfterCurrent = () => {
|
|
queueStore.queueAfterCurrent(songs.value)
|
|
close()
|
|
}
|
|
|
|
const queueSongsToBottom = () => {
|
|
queueStore.queue(songs.value)
|
|
close()
|
|
}
|
|
|
|
const queueSongsToTop = () => {
|
|
queueStore.queueToTop(songs.value)
|
|
close()
|
|
}
|
|
|
|
const addSongsToFavorite = async () => {
|
|
await favoriteStore.like(songs.value)
|
|
close()
|
|
}
|
|
|
|
const addSongsToExistingPlaylist = async (playlist: Playlist) => {
|
|
await playlistStore.addSongs(playlist, songs.value)
|
|
alerts.success(`Added ${pluralize(songs.value.length, 'song')} into "${playlist.name}."`)
|
|
close()
|
|
}
|
|
|
|
return {
|
|
queueSongsAfterCurrent,
|
|
queueSongsToBottom,
|
|
queueSongsToTop,
|
|
addSongsToFavorite,
|
|
addSongsToExistingPlaylist
|
|
}
|
|
}
|