2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
2022-05-10 12:09:31 +00:00
|
|
|
<div
|
|
|
|
:class="{ playing, selected: item.selected }"
|
|
|
|
class="song-item"
|
|
|
|
data-testid="song-item"
|
|
|
|
@dblclick.prevent.stop="play"
|
|
|
|
>
|
2022-04-23 22:31:40 +00:00
|
|
|
<span v-if="columns.includes('track')" class="track-number text-secondary">{{ song.track || '' }}</span>
|
|
|
|
<span v-if="columns.includes('title')" class="title">{{ song.title }}</span>
|
|
|
|
<span v-if="columns.includes('artist')" class="artist">{{ song.artist.name }}</span>
|
|
|
|
<span v-if="columns.includes('album')" class="album">{{ song.album.name }}</span>
|
|
|
|
<span v-if="columns.includes('length')" class="time text-secondary">{{ song.fmtLength }}</span>
|
2022-04-15 17:00:08 +00:00
|
|
|
<span class="favorite">
|
|
|
|
<LikeButton :song="song"/>
|
|
|
|
</span>
|
2022-05-10 12:09:31 +00:00
|
|
|
<span class="play" data-testid="song-item-play" role="button" @click.stop="doPlayback">
|
2022-04-15 14:24:30 +00:00
|
|
|
<i class="fa fa-pause-circle" v-if="song.playbackState === 'Playing'"></i>
|
|
|
|
<i class="fa fa-play-circle" v-else></i>
|
2022-04-15 17:00:08 +00:00
|
|
|
</span>
|
|
|
|
</div>
|
2022-04-15 14:24:30 +00:00
|
|
|
</template>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<script lang="ts" setup>
|
2022-04-29 08:40:34 +00:00
|
|
|
import { computed, defineAsyncComponent, toRefs } from 'vue'
|
2022-04-24 08:50:45 +00:00
|
|
|
import { playbackService } from '@/services'
|
2022-04-15 14:24:30 +00:00
|
|
|
import { queueStore } from '@/stores'
|
2022-04-15 17:00:08 +00:00
|
|
|
|
2022-04-20 15:57:53 +00:00
|
|
|
const LikeButton = defineAsyncComponent(() => import('@/components/song/SongLikeButton.vue'))
|
2022-04-15 17:00:08 +00:00
|
|
|
|
2022-04-29 08:40:34 +00:00
|
|
|
const props = defineProps<{ item: SongRow, columns: SongListColumn[] }>()
|
2022-04-15 17:00:08 +00:00
|
|
|
const { item, columns } = toRefs(props)
|
|
|
|
|
|
|
|
const song = computed(() => item.value.song)
|
|
|
|
const playing = computed(() => ['Playing', 'Paused'].includes(song.value.playbackState!))
|
|
|
|
|
2022-04-23 22:31:40 +00:00
|
|
|
const play = () => {
|
|
|
|
queueStore.queueIfNotQueued(song.value)
|
2022-04-24 08:50:45 +00:00
|
|
|
playbackService.play(song.value)
|
2022-04-15 17:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const doPlayback = () => {
|
|
|
|
switch (song.value.playbackState) {
|
|
|
|
case 'Playing':
|
2022-04-24 08:50:45 +00:00
|
|
|
playbackService.pause()
|
2022-04-15 17:00:08 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
case 'Paused':
|
2022-04-24 08:50:45 +00:00
|
|
|
playbackService.resume()
|
2022-04-15 17:00:08 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
default:
|
2022-04-23 22:31:40 +00:00
|
|
|
play()
|
2022-04-15 17:00:08 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.song-item {
|
|
|
|
border-bottom: 1px solid var(--color-bg-secondary);
|
|
|
|
max-width: 100% !important; // overriding .item
|
|
|
|
height: 35px;
|
2022-04-15 17:00:08 +00:00
|
|
|
display: flex;
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: rgba(255, 255, 255, .05);
|
|
|
|
}
|
|
|
|
|
|
|
|
.play {
|
|
|
|
i {
|
|
|
|
font-size: 1.5rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.favorite .fa-heart, .favorite:hover .fa-heart-o {
|
|
|
|
color: var(--color-maroon);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.selected {
|
|
|
|
background-color: rgba(255, 255, 255, .08);
|
|
|
|
}
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
&.playing span {
|
2022-04-15 14:24:30 +00:00
|
|
|
color: var(--color-highlight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|