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