2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
2022-05-10 12:09:31 +00:00
|
|
|
<div
|
2024-01-04 10:24:40 +00:00
|
|
|
:class="{ playing, external, selected: item.selected }"
|
2022-05-10 12:09:31 +00:00
|
|
|
class="song-item"
|
|
|
|
data-testid="song-item"
|
2022-07-15 15:23:12 +00:00
|
|
|
tabindex="0"
|
2022-11-12 21:38:31 +00:00
|
|
|
@dblclick.prevent.stop="play"
|
2022-05-10 12:09:31 +00:00
|
|
|
>
|
2022-11-12 21:38:31 +00:00
|
|
|
<span class="track-number">
|
2022-12-02 16:17:37 +00:00
|
|
|
<SoundBars v-if="song.playback_state === 'Playing'" />
|
2022-11-12 21:38:31 +00:00
|
|
|
<span v-else class="text-secondary">{{ song.track || '' }}</span>
|
2022-08-01 08:58:25 +00:00
|
|
|
</span>
|
2022-10-26 12:34:32 +00:00
|
|
|
<span class="thumbnail">
|
2022-12-02 16:17:37 +00:00
|
|
|
<SongThumbnail :song="song" />
|
2022-10-26 12:34:32 +00:00
|
|
|
</span>
|
2022-11-12 21:38:31 +00:00
|
|
|
<span class="title-artist">
|
2024-01-04 10:24:40 +00:00
|
|
|
<span class="title text-primary">
|
2024-03-19 22:48:12 +00:00
|
|
|
<span v-if="external" class="external-mark">
|
2024-01-04 10:24:40 +00:00
|
|
|
<Icon :icon="faSquareUpRight" />
|
|
|
|
</span>
|
|
|
|
{{ song.title }}
|
|
|
|
</span>
|
2022-11-12 21:38:31 +00:00
|
|
|
<span class="artist">
|
|
|
|
{{ song.artist_name }}
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
<span class="album">{{ song.album_name }}</span>
|
2024-01-18 11:13:05 +00:00
|
|
|
<template v-if="config.collaborative">
|
|
|
|
<span class="collaborator">
|
|
|
|
<UserAvatar :user="collaborator" width="24" />
|
|
|
|
</span>
|
|
|
|
<span class="added-at" :title="song.collaboration.added_at">{{ song.collaboration.fmt_added_at }}</span>
|
|
|
|
</template>
|
2022-11-12 21:38:31 +00:00
|
|
|
<span class="time">{{ fmtLength }}</span>
|
|
|
|
<span class="extra">
|
2022-12-02 16:17:37 +00:00
|
|
|
<LikeButton :song="song" />
|
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>
|
2024-01-04 10:24:40 +00:00
|
|
|
import { faSquareUpRight } from '@fortawesome/free-solid-svg-icons'
|
2022-07-05 18:01:33 +00:00
|
|
|
import { computed, toRefs } from 'vue'
|
2024-01-18 11:13:05 +00:00
|
|
|
import { requireInjection, secondsToHis } from '@/utils'
|
|
|
|
import { useAuthorization, useKoelPlus } from '@/composables'
|
|
|
|
import { SongListConfigKey } from '@/symbols'
|
2022-04-15 17:00:08 +00:00
|
|
|
|
2022-07-05 18:01:33 +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-10-26 12:34:32 +00:00
|
|
|
import SongThumbnail from '@/components/song/SongThumbnail.vue'
|
2024-01-18 11:13:05 +00:00
|
|
|
import UserAvatar from '@/components/user/UserAvatar.vue'
|
|
|
|
|
|
|
|
const [config] = requireInjection<[Partial<SongListConfig>]>(SongListConfigKey, [{}])
|
2022-04-15 17:00:08 +00:00
|
|
|
|
2024-01-04 10:24:40 +00:00
|
|
|
const { currentUser } = useAuthorization()
|
2024-01-08 16:59:05 +00:00
|
|
|
const { isPlus } = useKoelPlus()
|
2024-01-04 10:24:40 +00:00
|
|
|
|
2022-11-12 21:38:31 +00:00
|
|
|
const props = defineProps<{ item: SongRow }>()
|
|
|
|
const { item } = toRefs(props)
|
2022-04-15 17:00:08 +00:00
|
|
|
|
2024-03-25 22:59:38 +00:00
|
|
|
const emit = defineEmits<{ (e: 'play', song: Song): void }>()
|
|
|
|
|
2024-01-18 11:13:05 +00:00
|
|
|
const song = computed<Song | CollaborativeSong>(() => item.value.song)
|
2022-06-10 10:47:46 +00:00
|
|
|
const playing = computed(() => ['Playing', 'Paused'].includes(song.value.playback_state!))
|
2024-01-08 16:59:05 +00:00
|
|
|
const external = computed(() => isPlus.value && song.value.owner_id !== currentUser.value?.id)
|
2022-06-10 10:47:46 +00:00
|
|
|
const fmtLength = secondsToHis(song.value.length)
|
2022-04-15 17:00:08 +00:00
|
|
|
|
2024-03-25 22:59:38 +00:00
|
|
|
const collaborator = computed<Pick<User, 'name' | 'avatar'>>(() => (song.value as CollaborativeSong).collaboration.user)
|
2024-01-18 11:13:05 +00:00
|
|
|
|
2024-03-25 22:59:38 +00:00
|
|
|
const play = () => emit('play', song.value)
|
2022-04-15 14:24:30 +00:00
|
|
|
</script>
|
|
|
|
|
2024-04-04 20:13:35 +00:00
|
|
|
<style lang="postcss">
|
2022-04-15 14:24:30 +00:00
|
|
|
.song-item {
|
2022-10-13 15:18:47 +00:00
|
|
|
color: var(--color-text-secondary);
|
2022-04-15 14:24:30 +00:00
|
|
|
border-bottom: 1px solid var(--color-bg-secondary);
|
2024-04-04 20:13:35 +00:00
|
|
|
max-width: 100% !important; /* overriding .item */
|
2022-10-26 12:34:32 +00:00
|
|
|
height: 64px;
|
2022-04-15 17:00:08 +00:00
|
|
|
display: flex;
|
2022-10-26 12:34:32 +00:00
|
|
|
align-items: center;
|
2024-01-25 18:02:10 +00:00
|
|
|
transition: background-color .2s ease-in-out, box-shadow .2s ease-in-out;
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-15 15:23:12 +00:00
|
|
|
&:focus, &:focus-within {
|
2024-01-25 18:02:10 +00:00
|
|
|
box-shadow: 0 0 1px 1px var(--color-accent) inset !important;
|
2022-07-15 15:23:12 +00:00
|
|
|
border-radius: 4px;
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
2024-01-04 10:24:40 +00:00
|
|
|
.external-mark {
|
|
|
|
display: inline-block !important;
|
|
|
|
vertical-align: bottom;
|
|
|
|
margin-right: .2rem;
|
|
|
|
opacity: .5;
|
|
|
|
}
|
|
|
|
|
2022-10-26 12:34:32 +00:00
|
|
|
@media (hover: none) {
|
|
|
|
.cover {
|
|
|
|
.control {
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
|
|
|
|
&::before {
|
|
|
|
opacity: .7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-15 15:23:12 +00:00
|
|
|
&:hover {
|
|
|
|
background: rgba(255, 255, 255, .05);
|
2024-01-25 18:02:10 +00:00
|
|
|
box-shadow: 0 0 1px 1px rgba(255, 255, 255, .1) inset;
|
|
|
|
border-radius: 5px;
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
&.selected {
|
|
|
|
background-color: rgba(255, 255, 255, .08);
|
|
|
|
}
|
|
|
|
|
2022-10-13 15:18:47 +00:00
|
|
|
&.playing {
|
2022-11-12 21:38:31 +00:00
|
|
|
.title, .track-number, .favorite {
|
2022-10-13 15:18:47 +00:00
|
|
|
color: var(--color-accent) !important;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-12 21:38:31 +00:00
|
|
|
.title-artist {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
gap: 5px;
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
span {
|
|
|
|
overflow: hidden;
|
|
|
|
white-space: nowrap;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-13 15:18:47 +00:00
|
|
|
button {
|
|
|
|
color: currentColor;
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|