koel/resources/assets/js/components/song/AddToMenu.vue

97 lines
2.9 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
2024-04-04 22:20:42 +00:00
<div class="add-to w-full max-w-[256px] min-w-[200px] p-3 space-y-3" data-testid="add-to-menu" tabindex="0">
2022-04-15 14:24:30 +00:00
<section class="existing-playlists">
2024-04-04 22:20:42 +00:00
<p class="mb-2 text-[0.9rem]">Add {{ pluralize(songs, 'song') }} to</p>
2022-04-15 14:24:30 +00:00
2024-04-04 22:20:42 +00:00
<ul v-koel-overflow-fade class="relative max-h-48 overflow-y-scroll space-y-1.5">
2022-04-15 14:24:30 +00:00
<template v-if="config.queue">
<template v-if="queue.length">
<li
v-if="currentSong"
class="queue-after-current"
data-testid="queue-after-current"
tabindex="0"
@click="queueSongsAfterCurrent"
>
After Current Song
</li>
<li class="bottom-queue" data-testid="queue-bottom" tabindex="0" @click="queueSongsToBottom">
Bottom of Queue
</li>
<li class="top-queue" data-testid="queue-top" tabindex="0" @click="queueSongsToTop">Top of Queue</li>
</template>
<li v-else data-testid="queue" tabindex="0" @click="queueSongsToBottom">Queue</li>
2022-04-15 14:24:30 +00:00
</template>
<li
v-if="config.favorites"
2022-04-15 14:24:30 +00:00
class="favorites"
data-testid="add-to-favorites"
2022-04-15 14:24:30 +00:00
tabindex="0"
@click="addSongsToFavorite"
2022-04-15 14:24:30 +00:00
>
Favorites
</li>
<li
v-for="playlist in playlists"
:key="playlist.id"
class="playlist"
data-testid="add-to-playlist"
tabindex="0"
@click="addSongsToExistingPlaylist(playlist)"
>
{{ playlist.name }}
</li>
2022-04-15 14:24:30 +00:00
</ul>
</section>
2024-04-04 22:20:42 +00:00
<Btn
class="!w-full !border !border-solid !border-white/20"
transparent
@click.prevent="addSongsToNewPlaylist"
>
New Playlist
</Btn>
2022-04-15 14:24:30 +00:00
</div>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
2024-03-19 22:48:12 +00:00
import { computed, toRef, toRefs, watch } from 'vue'
2022-11-18 18:44:20 +00:00
import { pluralize } from '@/utils'
import { playlistStore, queueStore } from '@/stores'
import { useSongMenuMethods } from '@/composables'
2022-04-15 14:24:30 +00:00
2024-04-04 22:20:42 +00:00
import Btn from '@/components/ui/form/Btn.vue'
2022-04-15 17:00:08 +00:00
const props = defineProps<{ songs: Song[], config: AddToMenuConfig }>()
const { songs, config } = toRefs(props)
2022-04-15 17:00:08 +00:00
const queue = toRef(queueStore.state, 'songs')
const currentSong = queueStore.current
const allPlaylists = toRef(playlistStore.state, 'playlists')
2024-01-24 22:39:47 +00:00
const playlists = computed(() => allPlaylists.value.filter(({ is_smart }) => !is_smart))
2022-04-15 17:00:08 +00:00
const emit = defineEmits<{ (e: 'closing'): void }>()
2022-04-15 17:00:08 +00:00
const close = () => emit('closing')
const {
queueSongsAfterCurrent,
queueSongsToBottom,
queueSongsToTop,
addSongsToFavorite,
addSongsToExistingPlaylist,
addSongsToNewPlaylist
2022-04-20 10:20:09 +00:00
} = useSongMenuMethods(songs, close)
2022-04-15 17:00:08 +00:00
watch(songs, () => songs.value.length || close())
2022-04-15 14:24:30 +00:00
</script>
2024-04-04 20:13:35 +00:00
<style lang="postcss" scoped>
2024-04-04 22:20:42 +00:00
li {
@apply h-9 leading-9 py-0 px-3 whitespace-nowrap overflow-hidden text-ellipsis rounded bg-white/5 cursor-pointer
hover:bg-k-highlight hover:text-k-text-primary;
2022-04-15 14:24:30 +00:00
}
</style>