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-05-19 05:49:42 +00:00
<p class="mb-2 text-[0.9rem]">Add {{ pluralize(playables, 'item') }} 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
2024-05-19 05:49:42 +00:00
v-if="currentPlayable"
class="queue-after-current"
data-testid="queue-after-current"
tabindex="0"
2024-05-19 05:49:42 +00:00
@click="queueAfterCurrent"
>
2024-05-19 05:49:42 +00:00
After Current
</li>
2024-05-19 05:49:42 +00:00
<li class="bottom-queue" data-testid="queue-bottom" tabindex="0" @click="queueToBottom">
Bottom of Queue
</li>
2024-05-19 05:49:42 +00:00
<li class="top-queue" data-testid="queue-top" tabindex="0" @click="queueToTop">Top of Queue</li>
</template>
2024-05-19 05:49:42 +00:00
<li v-else data-testid="queue" tabindex="0" @click="queueToBottom">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"
2024-05-19 05:49:42 +00:00
@click="addToFavorites"
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"
2024-05-19 05:49:42 +00:00
@click="addToExistingPlaylist(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
2024-05-19 05:49:42 +00:00
@click.prevent="addToNewPlaylist"
2024-04-04 22:20:42 +00:00
>
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'
2024-05-19 05:49:42 +00:00
import { usePlayableMenuMethods } 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
2024-05-19 05:49:42 +00:00
const props = defineProps<{ playables: Playable[], config: AddToMenuConfig }>()
const { playables, config } = toRefs(props)
2022-04-15 17:00:08 +00:00
2024-05-19 05:49:42 +00:00
const queue = toRef(queueStore.state, 'playables')
const currentPlayable = 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 {
2024-05-19 05:49:42 +00:00
queueAfterCurrent,
queueToBottom,
queueToTop,
addToFavorites,
addToExistingPlaylist,
addToNewPlaylist
} = usePlayableMenuMethods(playables, close)
2022-04-15 17:00:08 +00:00
2024-05-19 05:49:42 +00:00
watch(playables, () => playables.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
2024-04-23 21:01:27 +00:00
hover:bg-k-highlight hover:text-k-text-primary;
2022-04-15 14:24:30 +00:00
}
</style>