koel/resources/assets/js/components/song/SongThumbnail.vue

61 lines
1.8 KiB
Vue
Raw Normal View History

<template>
2024-05-19 05:49:42 +00:00
<button
2024-04-04 22:20:42 +00:00
:style="{ backgroundImage: `url(${defaultCover})` }"
2024-05-19 05:49:42 +00:00
:title="title"
class="song-thumbnail w-[48px] aspect-square bg-cover relative rounded overflow-hidden active:scale-95"
@click.prevent="playOrPause"
2024-04-04 22:20:42 +00:00
>
2024-02-24 15:37:01 +00:00
<img
v-koel-hide-broken-icon
2024-05-19 05:49:42 +00:00
alt="Cover image"
:src="src"
class="w-full aspect-square object-cover"
2024-02-24 15:37:01 +00:00
loading="lazy"
>
2024-05-19 05:49:42 +00:00
<span class="absolute top-0 left-0 w-full h-full group-hover:bg-black/40 z-10" />
<span
class="absolute flex opacity-0 items-center justify-center w-[24px] aspect-square rounded-full top-1/2
left-1/2 -translate-x-1/2 -translate-y-1/2 bg-k-highlight group-hover:opacity-100 duration-500 transition z-20"
2024-04-04 22:20:42 +00:00
>
2024-05-19 05:49:42 +00:00
<Icon v-if="song.playback_state === 'Playing'" :icon="faPause" class="text-white" />
<Icon v-else :icon="faPlay" class="text-white ml-0.5" />
</span>
</button>
</template>
<script lang="ts" setup>
import { computed, toRefs } from 'vue'
import { faPause, faPlay } from '@fortawesome/free-solid-svg-icons'
2024-05-19 05:49:42 +00:00
import { defaultCover, getPlayableProp } from '@/utils'
import { playbackService } from '@/services'
2024-05-19 05:49:42 +00:00
const props = defineProps<{ song: Playable }>()
const { song } = toRefs(props)
2024-05-19 05:49:42 +00:00
const src = computed(() => getPlayableProp<string>(song.value, 'album_cover', 'episode_image'))
const play = () => playbackService.play(song.value)
const title = computed(() => {
if (song.value.playback_state === 'Playing') {
return 'Pause'
}
if (song.value.playback_state === 'Paused') {
return 'Resume'
}
return 'Play'
})
2024-05-19 05:49:42 +00:00
const playOrPause = () => {
if (song.value.playback_state === 'Stopped') {
play()
} else if (song.value.playback_state === 'Paused') {
playbackService.resume()
} else {
playbackService.pause()
}
}
</script>