2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
|
|
|
<article
|
2022-06-10 10:47:46 +00:00
|
|
|
:class="{ playing: song.playback_state === 'Playing' || song.playback_state === 'Paused' }"
|
2022-05-09 12:54:41 +00:00
|
|
|
data-testid="song-card"
|
2022-04-23 22:15:08 +00:00
|
|
|
draggable="true"
|
2022-04-15 14:24:30 +00:00
|
|
|
tabindex="0"
|
2022-04-23 22:15:08 +00:00
|
|
|
@dragstart="dragStart"
|
2022-04-30 11:55:54 +00:00
|
|
|
@contextmenu.prevent="requestContextMenu"
|
2022-04-23 22:15:08 +00:00
|
|
|
@dblclick.prevent="play"
|
2022-04-15 14:24:30 +00:00
|
|
|
>
|
2022-06-10 10:47:46 +00:00
|
|
|
<span :style="{ backgroundImage: `url(${song.album_cover})` }" class="cover">
|
2022-05-09 12:54:41 +00:00
|
|
|
<a class="control" @click.prevent="changeSongState" data-testid="play-control">
|
2022-06-10 10:47:46 +00:00
|
|
|
<i v-if="song.playback_state !== 'Playing'" class="fa fa-play"/>
|
2022-04-15 14:24:30 +00:00
|
|
|
<i class="fa fa-pause" v-else/>
|
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
<span class="main">
|
|
|
|
<span class="details">
|
2022-06-10 10:47:46 +00:00
|
|
|
<span v-if="showPlayCount" :style="{ width: `${song.play_count*100/topPlayCount}%` }" class="play-count"/>
|
2022-04-15 14:24:30 +00:00
|
|
|
{{ song.title }}
|
|
|
|
<span class="by text-secondary">
|
2022-06-10 10:47:46 +00:00
|
|
|
<a :href="`#!/artist/${song.artist_id}`">{{ song.artist_name }}</a>
|
|
|
|
<template v-if="showPlayCount"> - {{ pluralize(song.play_count, 'play') }}</template>
|
2022-04-15 14:24:30 +00:00
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
<span class="favorite">
|
2022-04-20 15:57:53 +00:00
|
|
|
<LikeButton :song="song"/>
|
2022-04-15 14:24:30 +00:00
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</article>
|
|
|
|
</template>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<script lang="ts" setup>
|
2022-04-20 09:37:22 +00:00
|
|
|
import { computed, defineAsyncComponent, toRefs } from 'vue'
|
2022-04-15 17:00:08 +00:00
|
|
|
import { eventBus, pluralize, startDragging } from '@/utils'
|
2022-04-15 14:24:30 +00:00
|
|
|
import { queueStore } from '@/stores'
|
2022-04-24 08:50:45 +00:00
|
|
|
import { playbackService } from '@/services'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-20 15:57:53 +00:00
|
|
|
const LikeButton = defineAsyncComponent(() => import('@/components/song/SongLikeButton.vue'))
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-20 09:37:22 +00:00
|
|
|
const props = withDefaults(defineProps<{ song: Song, topPlayCount?: number }>(), { topPlayCount: 0 })
|
2022-04-15 17:00:08 +00:00
|
|
|
const { song, topPlayCount } = toRefs(props)
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-06-10 10:47:46 +00:00
|
|
|
const showPlayCount = computed(() => Boolean(topPlayCount && song.value.play_count))
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const requestContextMenu = (event: MouseEvent) => eventBus.emit('SONG_CONTEXT_MENU_REQUESTED', event, song.value)
|
|
|
|
const dragStart = (event: DragEvent) => startDragging(event, song.value, 'Song')
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const play = () => {
|
2022-04-23 22:31:40 +00:00
|
|
|
queueStore.queueIfNotQueued(song.value)
|
2022-04-24 08:50:45 +00:00
|
|
|
playbackService.play(song.value)
|
2022-04-15 17:00:08 +00:00
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const changeSongState = () => {
|
2022-06-10 10:47:46 +00:00
|
|
|
if (song.value.playback_state === 'Stopped') {
|
2022-04-15 17:00:08 +00:00
|
|
|
play()
|
2022-06-10 10:47:46 +00:00
|
|
|
} else if (song.value.playback_state === 'Paused') {
|
2022-04-24 08:50:45 +00:00
|
|
|
playbackService.resume()
|
2022-04-15 17:00:08 +00:00
|
|
|
} else {
|
2022-04-24 08:50:45 +00:00
|
|
|
playbackService.pause()
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
2022-04-15 17:00:08 +00:00
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
article {
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
&.playing {
|
|
|
|
color: var(--color-highlight);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover .cover, &:focus .cover {
|
|
|
|
.control {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
&::before {
|
|
|
|
opacity: .7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.cover {
|
|
|
|
flex: 0 0 48px;
|
|
|
|
height: 48px;
|
|
|
|
background-size: cover;
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
@include vertical-center();
|
|
|
|
|
|
|
|
&::before {
|
|
|
|
content: " ";
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
pointer-events: none;
|
|
|
|
background: #000;
|
|
|
|
opacity: 0;
|
|
|
|
|
|
|
|
@media (hover: none) {
|
|
|
|
opacity: .7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.control {
|
|
|
|
border-radius: 50%;
|
|
|
|
width: 28px;
|
|
|
|
height: 28px;
|
|
|
|
background: rgba(0, 0, 0, .7);
|
|
|
|
line-height: 2rem;
|
|
|
|
font-size: 1rem;
|
|
|
|
text-align: center;
|
|
|
|
z-index: 1;
|
|
|
|
display: none;
|
|
|
|
color: var(--color-text-primary);
|
|
|
|
transition: .3s;
|
|
|
|
|
|
|
|
@media (hover: none) {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.main {
|
|
|
|
flex: 1;
|
|
|
|
padding: 4px 8px;
|
|
|
|
position: relative;
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
.play-count {
|
|
|
|
background: rgba(255, 255, 255, 0.08);
|
|
|
|
position: absolute;
|
|
|
|
height: 100%;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.by {
|
|
|
|
display: block;
|
|
|
|
font-size: .9rem;
|
|
|
|
margin-top: 2px;
|
|
|
|
opacity: .8;
|
|
|
|
|
|
|
|
a {
|
|
|
|
color: var(--color-text-primary);
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
color: var(--color-highlight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.details {
|
|
|
|
flex: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|