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'
|
|
|
|
import { CurrentSongKey } 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()
|
2022-12-19 15:44:48 +00:00
|
|
|
const song = requireInjection(CurrentSongKey, 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
|
|
|
|
|
|
|
|
let songs: Song[]
|
|
|
|
|
2022-11-18 18:44:20 +00:00
|
|
|
switch (getCurrentScreen()) {
|
2022-10-13 15:18:47 +00:00
|
|
|
case 'Album':
|
2022-11-18 18:44:20 +00:00
|
|
|
songs = await songStore.fetchForAlbum(parseInt(getRouteParam('id')!))
|
2022-10-13 15:18:47 +00:00
|
|
|
break
|
|
|
|
case 'Artist':
|
2022-11-18 18:44:20 +00:00
|
|
|
songs = await songStore.fetchForArtist(parseInt(getRouteParam('id')!))
|
2022-10-13 15:18:47 +00:00
|
|
|
break
|
|
|
|
case 'Playlist':
|
2024-01-18 11:13:05 +00:00
|
|
|
songs = await songStore.fetchForPlaylist(getRouteParam('id')!)
|
2022-10-13 15:18:47 +00:00
|
|
|
break
|
|
|
|
case 'Favorites':
|
|
|
|
songs = await favoriteStore.fetch()
|
|
|
|
break
|
|
|
|
case 'RecentlyPlayed':
|
|
|
|
songs = await recentlyPlayedStore.fetch()
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
songs = await queueStore.fetchRandom()
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2022-10-21 20:06:43 +00:00
|
|
|
playbackService.queueAndPlay(songs)
|
2022-11-18 18:44:20 +00:00
|
|
|
go('queue')
|
2022-10-13 15:18:47 +00:00
|
|
|
}
|
|
|
|
</script>
|