refactor: useSongMenuMethods

This commit is contained in:
Phan An 2024-04-29 22:35:55 +02:00
parent ab5b3d6ef7
commit fe449cd3cd
4 changed files with 13 additions and 38 deletions

View file

@ -6,7 +6,7 @@
}
li {
@apply relative px-4 py-1.5 whitespace-nowrap hover:bg-k-highlight hover:text-k-text-primary;
@apply relative px-4 py-1.5 whitespace-nowrap hover:bg-k-highlight hover:text-k-text-primary leading-7;
&.separator {
@apply pointer-events-none p-0 border-b border-b-white/10;

View file

@ -28,7 +28,7 @@
class="favorites"
data-testid="add-to-favorites"
tabindex="0"
@click="addSongsToFavorite"
@click="addSongsToFavorites"
>
Favorites
</li>
@ -80,7 +80,7 @@ const {
queueSongsAfterCurrent,
queueSongsToBottom,
queueSongsToTop,
addSongsToFavorite,
addSongsToFavorites,
addSongsToExistingPlaylist,
addSongsToNewPlaylist
} = useSongMenuMethods(songs, close)

View file

@ -19,7 +19,7 @@
<li v-else @click="queueSongsToBottom">Queue</li>
<template v-if="!isFavoritesScreen">
<li class="separator" />
<li @click="addSongsToFavorite">Favorites</li>
<li @click="addSongsToFavorites">Favorites</li>
</template>
<li v-if="normalPlaylists.length" class="separator" />
<template class="d-block">
@ -93,7 +93,7 @@ const {
queueSongsAfterCurrent,
queueSongsToBottom,
queueSongsToTop,
addSongsToFavorite,
addSongsToFavorites,
addSongsToExistingPlaylist,
addSongsToNewPlaylist
} = useSongMenuMethods(songs, close)

View file

@ -6,42 +6,17 @@ import { eventBus } from '@/utils'
export const useSongMenuMethods = (songs: Ref<Song[]>, close: Closure) => {
const { addSongsToPlaylist } = usePlaylistManagement()
const queueSongsAfterCurrent = () => {
const trigger = async (cb: Closure) => {
close()
queueStore.queueAfterCurrent(songs.value)
}
const queueSongsToBottom = () => {
close()
queueStore.queue(songs.value)
}
const queueSongsToTop = () => {
close()
queueStore.queueToTop(songs.value)
}
const addSongsToFavorite = async () => {
close()
await favoriteStore.like(songs.value)
}
const addSongsToExistingPlaylist = async (playlist: Playlist) => {
close()
await addSongsToPlaylist(playlist, songs.value)
}
const addSongsToNewPlaylist = () => {
close()
eventBus.emit('MODAL_SHOW_CREATE_PLAYLIST_FORM', null, songs.value)
await cb()
}
return {
queueSongsAfterCurrent,
queueSongsToBottom,
queueSongsToTop,
addSongsToFavorite,
addSongsToExistingPlaylist,
addSongsToNewPlaylist
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))
}
}