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

91 lines
2.5 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<div
:class="{ playing, selected: item.selected }"
class="song-item"
data-testid="song-item"
@dblclick.prevent.stop="play"
tabindex="0"
>
2022-08-01 08:58:25 +00:00
<span v-if="columns.includes('track')" class="track-number">
<SoundBars v-if="song.playback_state === 'Playing'"/>
<span class="text-secondary" v-else>{{ song.track || '' }}</span>
</span>
<span v-if="columns.includes('title')" class="title">{{ song.title }}</span>
2022-06-10 10:47:46 +00:00
<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">{{ fmtLength }}</span>
2022-04-15 17:00:08 +00:00
<span class="favorite">
<LikeButton :song="song"/>
</span>
<span class="play" data-testid="song-item-play" role="button" @click.stop="doPlayback">
2022-07-15 07:23:55 +00:00
<icon v-if="song.playback_state === 'Playing'" :icon="faCirclePause"/>
<icon v-else :icon="faCirclePlay"/>
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-07-15 07:23:55 +00:00
import { faCirclePause, faCirclePlay } from '@fortawesome/free-solid-svg-icons'
import { computed, 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-06-10 10:47:46 +00:00
import { secondsToHis } from '@/utils'
2022-04-15 17:00:08 +00:00
import LikeButton from '@/components/song/SongLikeButton.vue'
2022-08-01 08:58:25 +00:00
import SoundBars from '@/components/ui/SoundBars.vue'
2022-04-15 17:00:08 +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)
2022-06-10 10:47:46 +00:00
const playing = computed(() => ['Playing', 'Paused'].includes(song.value.playback_state!))
const fmtLength = secondsToHis(song.value.length)
2022-04-15 17:00:08 +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 = () => {
2022-06-10 10:47:46 +00:00
switch (song.value.playback_state) {
2022-04-15 17:00:08 +00:00
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:
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
&:focus, &:focus-within {
box-shadow: 0 0 1px 1px var(--color-accent) inset;
border-radius: 4px;
2022-04-15 14:24:30 +00:00
}
&:hover {
background: rgba(255, 255, 255, .05);
2022-04-15 14:24:30 +00:00
}
&.selected {
background-color: rgba(255, 255, 255, .08);
}
2022-08-01 08:58:25 +00:00
&.playing > span {
color: var(--color-accent);
2022-04-15 14:24:30 +00:00
}
}
</style>