2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
2024-04-04 22:20:42 +00:00
|
|
|
<ScreenBase>
|
|
|
|
<template #header>
|
|
|
|
<ScreenHeader :layout="songs.length === 0 ? 'collapsed' : headerLayout">
|
|
|
|
Current Queue
|
|
|
|
<ControlsToggle v-model="showingControls" />
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2024-04-04 22:20:42 +00:00
|
|
|
<template #thumbnail>
|
|
|
|
<ThumbnailStack :thumbnails="thumbnails" />
|
|
|
|
</template>
|
2022-07-16 09:52:39 +00:00
|
|
|
|
2024-04-04 22:20:42 +00:00
|
|
|
<template v-if="songs.length" #meta>
|
2024-05-19 05:49:42 +00:00
|
|
|
<span>{{ pluralize(songs, 'item') }}</span>
|
2024-04-04 22:20:42 +00:00
|
|
|
<span>{{ duration }}</span>
|
|
|
|
</template>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2024-04-04 22:20:42 +00:00
|
|
|
<template #controls>
|
|
|
|
<SongListControls
|
|
|
|
v-if="songs.length && (!isPhone || showingControls)"
|
|
|
|
:config="config"
|
|
|
|
@filter="applyFilter"
|
|
|
|
@clear-queue="clearQueue"
|
|
|
|
@play-all="playAll"
|
|
|
|
@play-selected="playSelected"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</ScreenHeader>
|
|
|
|
</template>
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2024-04-04 22:20:42 +00:00
|
|
|
<SongListSkeleton v-if="loading" class="-m-6" />
|
2022-04-20 09:37:22 +00:00
|
|
|
<SongList
|
|
|
|
v-if="songs.length"
|
2022-04-21 18:12:11 +00:00
|
|
|
ref="songList"
|
2024-04-04 22:20:42 +00:00
|
|
|
class="-m-6"
|
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-12-02 16:17:37 +00:00
|
|
|
<template #icon>
|
2023-11-10 13:16:06 +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-11-29 10:18:58 +00:00
|
|
|
<a class="start" @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>
|
2024-04-04 22:20:42 +00:00
|
|
|
</ScreenBase>
|
2022-04-15 14:24:30 +00:00
|
|
|
</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'
|
2024-01-22 23:16:57 +00:00
|
|
|
import { computed, ref, toRef } from 'vue'
|
2024-04-23 11:24:29 +00:00
|
|
|
import { pluralize } from '@/utils'
|
2022-08-01 11:40:52 +00:00
|
|
|
import { commonStore, queueStore, songStore } from '@/stores'
|
2024-01-22 23:16:57 +00:00
|
|
|
import { cache, playbackService } from '@/services'
|
2024-04-23 11:24:29 +00:00
|
|
|
import { useErrorHandler, useRouter, useSongList, useSongListControls } from '@/composables'
|
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'
|
2024-04-04 22:20:42 +00:00
|
|
|
import ScreenBase from '@/components/screens/ScreenBase.vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2024-01-11 19:26:38 +00:00
|
|
|
const { go, onScreenActivated } = useRouter()
|
2022-10-08 10:54:25 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const {
|
|
|
|
SongList,
|
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,
|
2024-05-19 05:49:42 +00:00
|
|
|
selectedPlayables,
|
2022-04-15 17:00:08 +00:00
|
|
|
showingControls,
|
|
|
|
isPhone,
|
|
|
|
playSelected,
|
2022-12-17 12:09:22 +00:00
|
|
|
applyFilter,
|
2024-10-13 17:37:01 +00:00
|
|
|
onScrollBreakpoint,
|
2024-05-19 05:49:42 +00:00
|
|
|
} = useSongList(toRef(queueStore.state, 'playables'), { type: 'Queue' }, { reorderable: true, sortable: false })
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2024-01-18 11:13:05 +00:00
|
|
|
const { SongListControls, config } = useSongListControls('Queue')
|
|
|
|
|
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-11-18 18:44:20 +00:00
|
|
|
go('queue')
|
2022-10-08 10:54:25 +00:00
|
|
|
}
|
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()
|
2024-04-23 11:24:29 +00:00
|
|
|
} catch (error: unknown) {
|
|
|
|
useErrorHandler('dialog').handleHttpError(error)
|
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-12-19 15:44:48 +00:00
|
|
|
const clearQueue = () => {
|
|
|
|
playbackService.stop()
|
|
|
|
queueStore.clear()
|
|
|
|
}
|
|
|
|
|
2024-06-07 12:53:24 +00:00
|
|
|
const removeSelected = async () => {
|
2024-10-13 17:37:01 +00:00
|
|
|
if (!selectedPlayables.value.length) {
|
|
|
|
return
|
|
|
|
}
|
2022-12-19 15:44:48 +00:00
|
|
|
|
|
|
|
const currentSongId = queueStore.current?.id
|
2024-05-19 05:49:42 +00:00
|
|
|
queueStore.unqueue(selectedPlayables.value)
|
2022-12-19 15:44:48 +00:00
|
|
|
|
2024-05-19 05:49:42 +00:00
|
|
|
if (currentSongId && selectedPlayables.value.find(({ id }) => id === currentSongId)) {
|
2024-06-07 12:53:24 +00:00
|
|
|
await playbackService.playNext()
|
2022-12-19 15:44:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-19 05:49:42 +00:00
|
|
|
const onPressEnter = () => selectedPlayables.value.length && playbackService.play(selectedPlayables.value[0])
|
|
|
|
const onReorder = (target: Playable, type: MoveType) => queueStore.move(selectedPlayables.value, target, type)
|
2022-08-01 11:40:52 +00:00
|
|
|
|
2024-01-11 19:26:38 +00:00
|
|
|
onScreenActivated('Queue', async () => {
|
2024-01-22 23:16:57 +00:00
|
|
|
if (!cache.get('song-to-queue')) {
|
2024-01-11 19:26:38 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-05-19 05:49:42 +00:00
|
|
|
let song: Playable | undefined
|
2022-08-01 11:40:52 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
loading.value = true
|
2024-01-22 23:16:57 +00:00
|
|
|
song = await songStore.resolve(cache.get('song-to-queue')!)
|
2022-08-01 11:40:52 +00:00
|
|
|
|
|
|
|
if (!song) {
|
2024-10-13 17:37:01 +00:00
|
|
|
throw new Error('Song not found')
|
2022-08-01 11:40:52 +00:00
|
|
|
}
|
2024-04-23 11:24:29 +00:00
|
|
|
} catch (error: unknown) {
|
|
|
|
useErrorHandler('dialog').handleHttpError(error)
|
2022-08-01 11:40:52 +00:00
|
|
|
return
|
|
|
|
} finally {
|
2024-01-22 23:16:57 +00:00
|
|
|
cache.remove('song-to-queue')
|
2022-08-01 11:40:52 +00:00
|
|
|
loading.value = false
|
|
|
|
}
|
|
|
|
|
2024-01-11 19:26:38 +00:00
|
|
|
queueStore.clearSilently()
|
|
|
|
queueStore.queue(song!)
|
2022-08-01 11:40:52 +00:00
|
|
|
})
|
2022-04-15 14:24:30 +00:00
|
|
|
</script>
|