2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
|
|
|
<section id="queueWrapper">
|
2022-07-17 08:58:05 +00:00
|
|
|
<ScreenHeader :layout="songs.length === 0 ? 'collapsed' : headerLayout">
|
2022-04-15 14:24:30 +00:00
|
|
|
Current Queue
|
2022-09-11 08:06:34 +00:00
|
|
|
<ControlsToggle v-model="showingControls"/>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-16 09:52:39 +00:00
|
|
|
<template v-slot:thumbnail>
|
|
|
|
<ThumbnailStack :thumbnails="thumbnails"/>
|
|
|
|
</template>
|
|
|
|
|
2022-10-08 10:54:25 +00:00
|
|
|
<template v-if="songs.length" v-slot:meta>
|
2022-09-03 08:32:09 +00:00
|
|
|
<span>{{ pluralize(songs, 'song') }}</span>
|
2022-07-10 17:15:56 +00:00
|
|
|
<span>{{ duration }}</span>
|
2022-04-15 14:24:30 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<template v-slot:controls>
|
2022-04-20 09:37:22 +00:00
|
|
|
<SongListControls
|
|
|
|
v-if="songs.length && (!isPhone || showingControls)"
|
2022-10-08 10:54:25 +00:00
|
|
|
:config="controlConfig"
|
|
|
|
@clearQueue="clearQueue"
|
2022-04-15 14:24:30 +00:00
|
|
|
@playAll="playAll"
|
|
|
|
@playSelected="playSelected"
|
|
|
|
/>
|
|
|
|
</template>
|
2022-04-20 09:37:22 +00:00
|
|
|
</ScreenHeader>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-08-01 11:40:52 +00:00
|
|
|
<SongListSkeleton v-if="loading"/>
|
2022-04-20 09:37:22 +00:00
|
|
|
<SongList
|
|
|
|
v-if="songs.length"
|
2022-04-21 18:12:11 +00:00
|
|
|
ref="songList"
|
2022-10-08 10:54:25 +00:00
|
|
|
@reorder="onReorder"
|
2022-04-21 18:12:11 +00:00
|
|
|
@press:delete="removeSelected"
|
|
|
|
@press:enter="onPressEnter"
|
2022-07-16 09:52:39 +00:00
|
|
|
@scroll-breakpoint="onScrollBreakpoint"
|
2022-04-15 14:24:30 +00:00
|
|
|
/>
|
|
|
|
|
2022-04-21 18:12:11 +00:00
|
|
|
<ScreenEmptyState v-else>
|
2022-04-15 14:24:30 +00:00
|
|
|
<template v-slot:icon>
|
2022-07-15 07:23:55 +00:00
|
|
|
<icon :icon="faCoffee"/>
|
2022-04-15 14:24:30 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
No songs queued.
|
2022-10-08 10:54:25 +00:00
|
|
|
<span v-if="libraryNotEmpty" class="d-block secondary">
|
2022-04-21 18:14:24 +00:00
|
|
|
How about
|
2022-10-08 10:54:25 +00:00
|
|
|
<a class="start" data-testid="shuffle-library" @click.prevent="shuffleSome">playing some random songs</a>?
|
2022-04-21 18:14:24 +00:00
|
|
|
</span>
|
2022-04-21 18:12:11 +00:00
|
|
|
</ScreenEmptyState>
|
2022-04-15 14:24:30 +00:00
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<script lang="ts" setup>
|
2022-07-15 07:23:55 +00:00
|
|
|
import { faCoffee } from '@fortawesome/free-solid-svg-icons'
|
2022-09-12 15:33:41 +00:00
|
|
|
import { computed, ref, toRef } from 'vue'
|
2022-08-01 11:40:52 +00:00
|
|
|
import { eventBus, logger, pluralize, requireInjection } from '@/utils'
|
|
|
|
import { commonStore, queueStore, songStore } from '@/stores'
|
2022-04-24 08:50:45 +00:00
|
|
|
import { playbackService } from '@/services'
|
2022-11-18 17:45:38 +00:00
|
|
|
import { useDialogBox, useSongList } from '@/composables'
|
|
|
|
import { RouterKey } from '@/symbols'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-07 18:05:46 +00:00
|
|
|
import ScreenHeader from '@/components/ui/ScreenHeader.vue'
|
|
|
|
import ScreenEmptyState from '@/components/ui/ScreenEmptyState.vue'
|
2022-07-30 15:08:20 +00:00
|
|
|
import SongListSkeleton from '@/components/ui/skeletons/SongListSkeleton.vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-10-08 10:54:25 +00:00
|
|
|
const router = requireInjection(RouterKey)
|
2022-11-18 17:45:38 +00:00
|
|
|
const { showErrorDialog } = useDialogBox()
|
2022-10-08 10:54:25 +00:00
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
const controlConfig: Partial<SongListControlsConfig> = { clearQueue: true }
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const {
|
|
|
|
SongList,
|
|
|
|
SongListControls,
|
2022-06-10 10:47:46 +00:00
|
|
|
ControlsToggle,
|
2022-07-16 09:52:39 +00:00
|
|
|
ThumbnailStack,
|
|
|
|
headerLayout,
|
2022-04-21 16:06:45 +00:00
|
|
|
songs,
|
2022-04-15 17:00:08 +00:00
|
|
|
songList,
|
2022-04-23 21:24:02 +00:00
|
|
|
duration,
|
2022-07-16 09:52:39 +00:00
|
|
|
thumbnails,
|
2022-04-15 17:00:08 +00:00
|
|
|
selectedSongs,
|
|
|
|
showingControls,
|
|
|
|
isPhone,
|
|
|
|
playSelected,
|
2022-07-16 09:52:39 +00:00
|
|
|
onScrollBreakpoint
|
2022-11-12 21:38:31 +00:00
|
|
|
} = useSongList(toRef(queueStore.state, 'songs'))
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-08-01 11:40:52 +00:00
|
|
|
const loading = ref(false)
|
2022-06-10 10:47:46 +00:00
|
|
|
const libraryNotEmpty = computed(() => commonStore.state.song_count > 0)
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-10-08 10:54:25 +00:00
|
|
|
const playAll = async (shuffle = true) => {
|
2022-10-21 20:06:43 +00:00
|
|
|
playbackService.queueAndPlay(songs.value, shuffle)
|
2022-10-08 10:54:25 +00:00
|
|
|
router.go('queue')
|
|
|
|
}
|
2022-06-10 10:47:46 +00:00
|
|
|
|
|
|
|
const shuffleSome = async () => {
|
2022-07-23 10:00:14 +00:00
|
|
|
try {
|
2022-08-01 11:40:52 +00:00
|
|
|
loading.value = true
|
2022-07-23 10:00:14 +00:00
|
|
|
await queueStore.fetchRandom()
|
|
|
|
await playbackService.playFirstInQueue()
|
|
|
|
} catch (e) {
|
2022-11-18 17:45:38 +00:00
|
|
|
showErrorDialog('Failed to fetch songs to play. Please try again.', 'Error')
|
2022-07-23 10:00:14 +00:00
|
|
|
logger.error(e)
|
2022-08-01 11:40:52 +00:00
|
|
|
} finally {
|
|
|
|
loading.value = false
|
2022-07-23 10:00:14 +00:00
|
|
|
}
|
2022-06-10 10:47:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const clearQueue = () => queueStore.clear()
|
2022-04-21 18:12:11 +00:00
|
|
|
const removeSelected = () => selectedSongs.value.length && queueStore.unqueue(selectedSongs.value)
|
2022-04-24 08:50:45 +00:00
|
|
|
const onPressEnter = () => selectedSongs.value.length && playbackService.play(selectedSongs.value[0])
|
2022-04-28 16:04:52 +00:00
|
|
|
const onReorder = (target: Song) => queueStore.move(selectedSongs.value, target)
|
2022-08-01 11:40:52 +00:00
|
|
|
|
2022-11-15 15:52:38 +00:00
|
|
|
eventBus.on('SONG_QUEUED_FROM_ROUTE', async id => {
|
2022-09-12 15:33:41 +00:00
|
|
|
let song: Song | undefined
|
2022-08-01 11:40:52 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
loading.value = true
|
|
|
|
song = await songStore.resolve(id)
|
|
|
|
|
|
|
|
if (!song) {
|
|
|
|
throw new Error('Song not found')
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2022-11-18 17:45:38 +00:00
|
|
|
showErrorDialog('Song not found. Please double check and try again.', 'Error')
|
2022-08-01 11:40:52 +00:00
|
|
|
logger.error(e)
|
|
|
|
return
|
|
|
|
} finally {
|
|
|
|
loading.value = false
|
|
|
|
}
|
|
|
|
|
2022-11-15 15:52:38 +00:00
|
|
|
queueStore.queueIfNotQueued(song!)
|
|
|
|
await playbackService.play(song!)
|
2022-08-01 11:40:52 +00:00
|
|
|
})
|
2022-04-15 14:24:30 +00:00
|
|
|
</script>
|