2022-10-13 15:18:47 +00:00
|
|
|
<template>
|
2024-04-04 22:20:42 +00:00
|
|
|
<FooterButton
|
|
|
|
:title="playing ? 'Pause' : 'Play or resume'"
|
|
|
|
class="!w-[3rem] rounded-full border-2 border-solid aspect-square !transition-transform hover:scale-125 !text-2xl
|
|
|
|
has-[.icon-play]:indent-[0.23rem]"
|
|
|
|
@click.prevent="toggle"
|
|
|
|
>
|
2023-11-10 13:16:06 +00:00
|
|
|
<Icon v-if="playing" :icon="faPause" />
|
2024-04-04 22:20:42 +00:00
|
|
|
<Icon v-else :icon="faPlay" class="icon-play" />
|
|
|
|
</FooterButton>
|
2022-10-13 15:18:47 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { faPause, faPlay } from '@fortawesome/free-solid-svg-icons'
|
|
|
|
import { computed, ref } from 'vue'
|
|
|
|
import { playbackService } from '@/services'
|
|
|
|
import { commonStore, favoriteStore, queueStore, recentlyPlayedStore, songStore } from '@/stores'
|
|
|
|
import { requireInjection } from '@/utils'
|
2022-11-18 18:44:20 +00:00
|
|
|
import { useRouter } from '@/composables'
|
2024-05-19 05:49:42 +00:00
|
|
|
import { CurrentPlayableKey } from '@/symbols'
|
2024-04-04 22:20:42 +00:00
|
|
|
import FooterButton from '@/components/layout/app-footer/FooterButton.vue'
|
2022-10-13 15:18:47 +00:00
|
|
|
|
2022-11-18 18:44:20 +00:00
|
|
|
const { getCurrentScreen, getRouteParam, go } = useRouter()
|
2024-05-19 05:49:42 +00:00
|
|
|
const song = requireInjection(CurrentPlayableKey, ref())
|
2022-10-13 15:18:47 +00:00
|
|
|
|
|
|
|
const libraryEmpty = computed(() => commonStore.state.song_count === 0)
|
|
|
|
const playing = computed(() => song.value?.playback_state === 'Playing')
|
|
|
|
|
|
|
|
const toggle = async () => song.value ? playbackService.toggle() : initiatePlayback()
|
|
|
|
|
|
|
|
const initiatePlayback = async () => {
|
|
|
|
if (libraryEmpty.value) return
|
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
let playables: Playable[]
|
2022-10-13 15:18:47 +00:00
|
|
|
|
2022-11-18 18:44:20 +00:00
|
|
|
switch (getCurrentScreen()) {
|
2022-10-13 15:18:47 +00:00
|
|
|
case 'Album':
|
2024-06-02 17:15:31 +00:00
|
|
|
playables = await songStore.fetchForAlbum(parseInt(getRouteParam('id')!))
|
2022-10-13 15:18:47 +00:00
|
|
|
break
|
|
|
|
case 'Artist':
|
2024-06-02 17:15:31 +00:00
|
|
|
playables = await songStore.fetchForArtist(parseInt(getRouteParam('id')!))
|
2022-10-13 15:18:47 +00:00
|
|
|
break
|
|
|
|
case 'Playlist':
|
2024-06-02 17:15:31 +00:00
|
|
|
playables = await songStore.fetchForPlaylist(getRouteParam('id')!)
|
2022-10-13 15:18:47 +00:00
|
|
|
break
|
|
|
|
case 'Favorites':
|
2024-06-02 17:15:31 +00:00
|
|
|
playables = await favoriteStore.fetch()
|
2022-10-13 15:18:47 +00:00
|
|
|
break
|
|
|
|
case 'RecentlyPlayed':
|
2024-06-02 17:15:31 +00:00
|
|
|
playables = await recentlyPlayedStore.fetch()
|
2022-10-13 15:18:47 +00:00
|
|
|
break
|
|
|
|
default:
|
2024-06-02 17:15:31 +00:00
|
|
|
playables = await queueStore.fetchRandom()
|
2022-10-13 15:18:47 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2024-06-07 12:53:24 +00:00
|
|
|
await playbackService.queueAndPlay(playables)
|
2022-11-18 18:44:20 +00:00
|
|
|
go('queue')
|
2022-10-13 15:18:47 +00:00
|
|
|
}
|
|
|
|
</script>
|