koel/resources/assets/js/components/ui/FooterPlayButton.vue

72 lines
2 KiB
Vue
Raw Normal View History

2022-10-13 15:18:47 +00:00
<template>
<button type="button" :class="playing ? 'playing' : 'stopped'" title="Play or resume" @click.prevent="toggle">
2023-11-10 13:16:06 +00:00
<Icon v-if="playing" :icon="faPause" />
<Icon v-else :icon="faPlay" />
2022-10-13 15:18:47 +00:00
</button>
</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'
2022-10-13 15:18:47 +00:00
2022-11-18 18:44:20 +00:00
const { getCurrentScreen, getRouteParam, go } = useRouter()
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':
2022-11-18 18:44:20 +00:00
songs = await songStore.fetchForPlaylist(parseInt(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>
<style lang="scss" scoped>
button {
width: 3rem !important;
2022-10-13 15:18:47 +00:00
border-radius: 50%;
border: 2px solid currentColor;
&.stopped {
text-indent: 0.2rem;
}
&:hover {
border-color: var(--color-text-primary) !important;
transform: scale(1.2);
}
}
</style>