2022-07-04 10:39:02 +00:00
|
|
|
import { Ref } from 'vue'
|
2022-04-26 13:36:26 +00:00
|
|
|
import { favoriteStore, playlistStore, queueStore } from '@/stores'
|
2022-07-26 09:51:19 +00:00
|
|
|
import { pluralize, requireInjection } from '@/utils'
|
|
|
|
import { DialogBoxKey, MessageToasterKey } from '@/symbols'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-05-05 15:30:10 +00:00
|
|
|
export const useSongMenuMethods = (songs: Ref<Song[]>, close: Closure) => {
|
2022-07-26 09:51:19 +00:00
|
|
|
const toaster = requireInjection(MessageToasterKey)
|
|
|
|
const dialog = requireInjection(DialogBoxKey)
|
|
|
|
|
2022-04-15 14:24:30 +00:00
|
|
|
const queueSongsAfterCurrent = () => {
|
|
|
|
close()
|
2022-06-10 10:47:46 +00:00
|
|
|
queueStore.queueAfterCurrent(songs.value)
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const queueSongsToBottom = () => {
|
|
|
|
close()
|
2022-06-10 10:47:46 +00:00
|
|
|
queueStore.queue(songs.value)
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const queueSongsToTop = () => {
|
|
|
|
close()
|
2022-06-10 10:47:46 +00:00
|
|
|
queueStore.queueToTop(songs.value)
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const addSongsToFavorite = async () => {
|
|
|
|
close()
|
2022-06-10 10:47:46 +00:00
|
|
|
await favoriteStore.like(songs.value)
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const addSongsToExistingPlaylist = async (playlist: Playlist) => {
|
|
|
|
close()
|
2022-07-19 08:19:57 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
await playlistStore.addSongs(playlist, songs.value)
|
2022-09-03 08:32:09 +00:00
|
|
|
toaster.value.success(`Added ${pluralize(songs.value, 'song')} into "${playlist.name}."`)
|
2022-07-19 08:19:57 +00:00
|
|
|
} catch (error) {
|
2022-07-26 09:51:19 +00:00
|
|
|
dialog.value.error('Something went wrong. Please try again.', 'Error')
|
2022-07-19 08:19:57 +00:00
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
queueSongsAfterCurrent,
|
|
|
|
queueSongsToBottom,
|
|
|
|
queueSongsToTop,
|
|
|
|
addSongsToFavorite,
|
|
|
|
addSongsToExistingPlaylist
|
|
|
|
}
|
|
|
|
}
|