2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
2024-03-19 22:48:12 +00:00
|
|
|
<div v-if="config" ref="el" class="song-list-controls" data-testid="song-list-controls">
|
2022-11-08 19:35:18 +00:00
|
|
|
<div class="wrapper">
|
|
|
|
<BtnGroup uppercased>
|
2022-12-06 10:28:48 +00:00
|
|
|
<template v-if="altPressed">
|
|
|
|
<Btn
|
|
|
|
v-if="selectedSongs.length < 2 && songs.length"
|
2024-03-19 22:48:12 +00:00
|
|
|
v-koel-tooltip.bottom
|
2022-12-06 10:28:48 +00:00
|
|
|
class="btn-play-all"
|
|
|
|
orange
|
2024-01-12 10:09:15 +00:00
|
|
|
title="Play all. Press Alt/⌥ to change mode."
|
2022-12-06 10:28:48 +00:00
|
|
|
@click.prevent="playAll"
|
|
|
|
>
|
2023-11-10 13:16:06 +00:00
|
|
|
<Icon :icon="faPlay" fixed-width />
|
2022-12-06 10:28:48 +00:00
|
|
|
All
|
|
|
|
</Btn>
|
|
|
|
|
|
|
|
<Btn
|
|
|
|
v-if="selectedSongs.length > 1"
|
2024-03-19 22:48:12 +00:00
|
|
|
v-koel-tooltip.bottom
|
2022-12-06 10:28:48 +00:00
|
|
|
class="btn-play-selected"
|
|
|
|
orange
|
2024-01-12 10:09:15 +00:00
|
|
|
title="Play selected. Press Alt/⌥ to change mode."
|
2022-12-06 10:28:48 +00:00
|
|
|
@click.prevent="playSelected"
|
|
|
|
>
|
2023-11-10 13:16:06 +00:00
|
|
|
<Icon :icon="faPlay" fixed-width />
|
2022-12-06 10:28:48 +00:00
|
|
|
Selected
|
|
|
|
</Btn>
|
2022-04-15 14:24:30 +00:00
|
|
|
</template>
|
|
|
|
|
2022-12-06 10:28:48 +00:00
|
|
|
<template v-else>
|
|
|
|
<Btn
|
|
|
|
v-if="selectedSongs.length < 2 && songs.length"
|
2024-03-19 22:48:12 +00:00
|
|
|
v-koel-tooltip.bottom
|
2022-12-06 10:28:48 +00:00
|
|
|
class="btn-shuffle-all"
|
|
|
|
data-testid="btn-shuffle-all"
|
|
|
|
orange
|
2024-01-12 10:09:15 +00:00
|
|
|
title="Shuffle all. Press Alt/⌥ to change mode."
|
2022-12-06 10:28:48 +00:00
|
|
|
@click.prevent="shuffle"
|
|
|
|
>
|
2023-11-10 13:16:06 +00:00
|
|
|
<Icon :icon="faRandom" fixed-width />
|
2022-12-06 10:28:48 +00:00
|
|
|
All
|
|
|
|
</Btn>
|
|
|
|
|
|
|
|
<Btn
|
|
|
|
v-if="selectedSongs.length > 1"
|
2024-03-19 22:48:12 +00:00
|
|
|
v-koel-tooltip.bottom
|
2022-12-06 10:28:48 +00:00
|
|
|
class="btn-shuffle-selected"
|
|
|
|
data-testid="btn-shuffle-selected"
|
|
|
|
orange
|
2024-01-12 10:09:15 +00:00
|
|
|
title="Shuffle selected. Press Alt/⌥ to change mode."
|
2022-12-06 10:28:48 +00:00
|
|
|
@click.prevent="shuffleSelected"
|
|
|
|
>
|
2023-11-10 13:16:06 +00:00
|
|
|
<Icon :icon="faRandom" fixed-width />
|
2022-12-06 10:28:48 +00:00
|
|
|
Selected
|
|
|
|
</Btn>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<Btn
|
|
|
|
v-if="showAddToButton"
|
|
|
|
ref="addToButton"
|
|
|
|
green @click.prevent.stop="toggleAddToMenu"
|
|
|
|
>
|
2022-11-08 19:35:18 +00:00
|
|
|
{{ showingAddToMenu ? 'Cancel' : 'Add To…' }}
|
|
|
|
</Btn>
|
|
|
|
|
2022-12-06 10:28:48 +00:00
|
|
|
<Btn v-if="config.clearQueue" red title="Clear current queue" @click.prevent="clearQueue">Clear</Btn>
|
2022-11-08 19:35:18 +00:00
|
|
|
</BtnGroup>
|
|
|
|
|
2022-12-17 12:09:22 +00:00
|
|
|
<BtnGroup v-if="config.refresh || config.deletePlaylist">
|
2022-11-08 19:35:18 +00:00
|
|
|
<Btn v-if="config.refresh" v-koel-tooltip green title="Refresh" @click.prevent="refresh">
|
2023-11-10 13:16:06 +00:00
|
|
|
<Icon :icon="faRotateRight" fixed-width />
|
2022-11-08 19:35:18 +00:00
|
|
|
</Btn>
|
|
|
|
|
|
|
|
<Btn
|
2022-12-06 10:28:48 +00:00
|
|
|
v-if="config.deletePlaylist"
|
2022-11-08 19:35:18 +00:00
|
|
|
v-koel-tooltip
|
|
|
|
class="del btn-delete-playlist"
|
|
|
|
red
|
|
|
|
title="Delete this playlist"
|
|
|
|
@click.prevent="deletePlaylist"
|
|
|
|
>
|
2023-11-10 13:16:06 +00:00
|
|
|
<Icon :icon="faTrashCan" />
|
2022-11-08 19:35:18 +00:00
|
|
|
</Btn>
|
|
|
|
</BtnGroup>
|
2022-12-17 12:09:22 +00:00
|
|
|
|
|
|
|
<BtnGroup v-if="config.filter && songs.length">
|
|
|
|
<SongListFilter @change="filter" />
|
|
|
|
</BtnGroup>
|
2022-11-08 19:35:18 +00:00
|
|
|
</div>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-11-13 15:18:24 +00:00
|
|
|
<div ref="addToMenu" v-koel-clickaway="closeAddToMenu" class="menu-wrapper">
|
2022-12-06 10:28:48 +00:00
|
|
|
<AddToMenu :config="config.addTo" :songs="selectedSongs" @closing="closeAddToMenu" />
|
2022-11-13 15:18:24 +00:00
|
|
|
</div>
|
2022-04-15 14:24:30 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<script lang="ts" setup>
|
2022-11-08 19:35:18 +00:00
|
|
|
import { faPlay, faRandom, faRotateRight, faTrashCan } from '@fortawesome/free-solid-svg-icons'
|
2024-01-18 11:13:05 +00:00
|
|
|
import { computed, defineAsyncComponent, nextTick, onBeforeUnmount, onMounted, Ref, ref, toRef, watch } from 'vue'
|
2022-06-10 10:47:46 +00:00
|
|
|
import { SelectedSongsKey, SongsKey } from '@/symbols'
|
2022-07-20 08:00:02 +00:00
|
|
|
import { requireInjection } from '@/utils'
|
2024-01-18 11:13:05 +00:00
|
|
|
import { useFloatingUi } from '@/composables'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-07 18:05:46 +00:00
|
|
|
import AddToMenu from '@/components/song/AddToMenu.vue'
|
|
|
|
import Btn from '@/components/ui/Btn.vue'
|
|
|
|
import BtnGroup from '@/components/ui/BtnGroup.vue'
|
2022-04-21 16:06:45 +00:00
|
|
|
|
2022-12-17 12:09:22 +00:00
|
|
|
const SongListFilter = defineAsyncComponent(() => import('@/components/song/SongListFilter.vue'))
|
|
|
|
|
2024-01-18 11:13:05 +00:00
|
|
|
const props = defineProps<{ config: SongListControlsConfig }>()
|
|
|
|
const config = toRef(props, 'config')
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-11-13 15:18:24 +00:00
|
|
|
const [songs] = requireInjection<[Ref<Song[]>]>(SongsKey)
|
2022-07-20 08:00:02 +00:00
|
|
|
const [selectedSongs] = requireInjection(SelectedSongsKey)
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-21 16:06:45 +00:00
|
|
|
const el = ref<HTMLElement>()
|
2022-12-02 16:17:37 +00:00
|
|
|
const addToButton = ref<InstanceType<typeof Btn>>()
|
2022-11-13 15:18:24 +00:00
|
|
|
const addToMenu = ref<HTMLDivElement>()
|
2022-04-15 17:00:08 +00:00
|
|
|
const showingAddToMenu = ref(false)
|
|
|
|
const altPressed = ref(false)
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-11-13 15:18:24 +00:00
|
|
|
const showAddToButton = computed(() => Boolean(selectedSongs.value.length))
|
2022-04-15 17:00:08 +00:00
|
|
|
|
2022-11-13 15:18:24 +00:00
|
|
|
const emit = defineEmits<{
|
|
|
|
(e: 'playAll' | 'playSelected', shuffle: boolean): void,
|
2022-12-17 12:09:22 +00:00
|
|
|
(e: 'filter', keywords: string): void,
|
2022-11-13 15:18:24 +00:00
|
|
|
(e: 'clearQueue' | 'deletePlaylist' | 'refresh'): void,
|
|
|
|
}>()
|
2022-04-15 17:00:08 +00:00
|
|
|
|
|
|
|
const shuffle = () => emit('playAll', true)
|
|
|
|
const shuffleSelected = () => emit('playSelected', true)
|
|
|
|
const playAll = () => emit('playAll', false)
|
|
|
|
const playSelected = () => emit('playSelected', false)
|
|
|
|
const clearQueue = () => emit('clearQueue')
|
|
|
|
const deletePlaylist = () => emit('deletePlaylist')
|
2022-11-08 19:35:18 +00:00
|
|
|
const refresh = () => emit('refresh')
|
2022-12-17 12:09:22 +00:00
|
|
|
const filter = (keywords: string) => emit('filter', keywords)
|
2022-04-21 16:28:12 +00:00
|
|
|
const registerKeydown = (event: KeyboardEvent) => event.key === 'Alt' && (altPressed.value = true)
|
|
|
|
const registerKeyup = (event: KeyboardEvent) => event.key === 'Alt' && (altPressed.value = false)
|
2022-04-15 17:00:08 +00:00
|
|
|
|
2022-11-13 15:18:24 +00:00
|
|
|
let usedFloatingUi: ReturnType<typeof useFloatingUi>
|
2022-04-15 17:00:08 +00:00
|
|
|
|
2022-11-13 15:18:24 +00:00
|
|
|
watch(showAddToButton, async showingButton => {
|
|
|
|
await nextTick()
|
|
|
|
|
|
|
|
if (showingButton) {
|
2022-12-02 16:17:37 +00:00
|
|
|
usedFloatingUi = useFloatingUi(addToButton.value!.button!, addToMenu, { autoTrigger: false })
|
2022-11-13 15:18:24 +00:00
|
|
|
usedFloatingUi.setup()
|
|
|
|
} else {
|
|
|
|
usedFloatingUi?.teardown()
|
2022-04-15 17:00:08 +00:00
|
|
|
}
|
2022-11-13 15:18:24 +00:00
|
|
|
}, { immediate: true })
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-11-13 15:18:24 +00:00
|
|
|
const closeAddToMenu = () => {
|
|
|
|
usedFloatingUi?.hide()
|
|
|
|
showingAddToMenu.value = false
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-11-13 15:18:24 +00:00
|
|
|
const toggleAddToMenu = () => {
|
|
|
|
showingAddToMenu.value ? usedFloatingUi?.hide() : usedFloatingUi?.show()
|
|
|
|
showingAddToMenu.value = !showingAddToMenu.value
|
2022-04-15 17:00:08 +00:00
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
onMounted(() => {
|
|
|
|
window.addEventListener('keydown', registerKeydown)
|
|
|
|
window.addEventListener('keyup', registerKeyup)
|
|
|
|
})
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-11-13 15:18:24 +00:00
|
|
|
onBeforeUnmount(() => {
|
2022-04-15 17:00:08 +00:00
|
|
|
window.removeEventListener('keydown', registerKeydown)
|
|
|
|
window.removeEventListener('keyup', registerKeyup)
|
2022-11-13 15:18:24 +00:00
|
|
|
|
|
|
|
usedFloatingUi?.teardown()
|
2022-04-15 14:24:30 +00:00
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.song-list-controls {
|
|
|
|
position: relative;
|
2022-11-08 19:35:18 +00:00
|
|
|
|
|
|
|
.wrapper {
|
|
|
|
display: flex;
|
|
|
|
gap: .5rem;
|
2022-12-17 12:09:22 +00:00
|
|
|
flex-wrap: wrap;
|
2022-11-08 19:35:18 +00:00
|
|
|
}
|
2022-11-13 15:18:24 +00:00
|
|
|
|
|
|
|
.menu-wrapper {
|
|
|
|
@include context-menu();
|
|
|
|
|
|
|
|
padding: 0;
|
|
|
|
display: none;
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
</style>
|