koel/resources/assets/js/components/screens/queue.vue
2022-04-20 11:37:22 +02:00

85 lines
2.3 KiB
Vue

<template>
<section id="queueWrapper">
<ScreenHeader>
Current Queue
<ControlsToggler :showing-controls="showingControls" @toggleControls="toggleControls"/>
<template v-slot:meta>
<span v-if="meta.songCount" data-test="list-meta">
{{ pluralize(meta.songCount, 'song') }} {{ meta.totalLength }}
</span>
</template>
<template v-slot:controls>
<SongListControls
v-if="songs.length && (!isPhone || showingControls)"
@playAll="playAll"
@playSelected="playSelected"
@clearQueue="clearQueue"
:songs="songs"
:config="songListControlConfig"
:selectedSongs="selectedSongs"
/>
</template>
</ScreenHeader>
<SongList
v-if="songs.length"
:items="songs"
:config="{ sortable: false }"
type="queue"
ref="songList"
/>
<ScreenPlaceholder v-else>
<template v-slot:icon>
<i class="fa fa-coffee"></i>
</template>
No songs queued.
<span class="secondary d-block" v-if="shouldShowShufflingAllLink">
How about
<a class="start" @click.prevent="shuffleAll">shuffling all songs</a>?
</span>
</ScreenPlaceholder>
</section>
</template>
<script lang="ts" setup>
import { pluralize } from '@/utils'
import { queueStore, songStore } from '@/stores'
import { playback } from '@/services'
import { useSongList } from '@/composables'
import { computed, defineAsyncComponent, reactive, toRef } from 'vue'
const ScreenHeader = defineAsyncComponent(() => import('@/components/ui/screen-header.vue'))
const ScreenPlaceholder = defineAsyncComponent(() => import('@/components/ui/screen-placeholder.vue'))
const {
SongList,
SongListControls,
ControlsToggler,
songList,
meta,
selectedSongs,
showingControls,
songListControlConfig,
isPhone,
playSelected,
toggleControls
} = useSongList({
clearQueue: true
})
const songs = toRef(queueStore.state, 'songs')
const songState = reactive(songStore.state)
const shouldShowShufflingAllLink = computed(() => songState.songs.length > 0)
const playAll = () => {
playback.queueAndPlay(songs.value.length ? songList.value.getAllSongsWithSort() : songStore.all)
}
const shuffleAll = async () => await playback.queueAndPlay(songStore.all, true)
const clearQueue = () => queueStore.clear()
</script>