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

78 lines
2.6 KiB
Vue
Raw Normal View History

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' }"
2024-04-04 22:20:42 +00:00
class="group flex gap-3 py-2 pl-2.5 pr-3 rounded-md items-center bg-k-bg-secondary border border-k-border
hover:border-white/15 transition-[border-color] duration-200 ease-in-out
focus:ring-1 focus:ring-k-accent focus-within:ring-1 focus-within:ring-k-accent"
2022-04-23 22:15:08 +00:00
draggable="true"
2022-04-15 14:24:30 +00:00
tabindex="0"
@dragstart="onDragStart"
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
>
2024-04-04 22:20:42 +00:00
<span>
<SongThumbnail :song="song" />
</span>
<main class="flex-1 flex items-start">
<div class="flex-1 space-y-1 overflow-hidden">
<h3 class="flex gap-2 overflow-hidden text-ellipsis whitespace-nowrap">
<ExternalMark v-if="external" />
2024-01-04 10:24:40 +00:00
{{ song.title }}
</h3>
2024-04-04 22:20:42 +00:00
<p class="text-k-text-secondary text-[0.9rem] opacity-80">
<a :href="`#/artist/${song.artist_id}`" class="!text-k-text-primary hover:!text-k-accent">
{{ song.artist_name }}
</a>
2022-07-30 15:08:20 +00:00
- {{ pluralize(song.play_count, 'play') }}
</p>
</div>
2024-04-04 22:20:42 +00:00
<LikeButton :song="song" class="opacity-0 text-k-text-secondary group-hover:opacity-100" />
2022-07-30 15:08:20 +00:00
</main>
2022-04-15 14:24:30 +00:00
</article>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
2024-01-04 10:24:40 +00:00
import { computed, toRefs } from 'vue'
import { eventBus, pluralize } 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'
2024-01-08 16:59:05 +00:00
import { useAuthorization, useDraggable, useKoelPlus } from '@/composables'
2022-04-15 14:24:30 +00:00
import SongThumbnail from '@/components/song/SongThumbnail.vue'
import LikeButton from '@/components/song/SongLikeButton.vue'
2024-04-04 22:20:42 +00:00
import ExternalMark from '@/components/ui/ExternalMark.vue'
2022-04-15 14:24:30 +00:00
2022-07-30 15:08:20 +00:00
const props = defineProps<{ song: Song }>()
const { song } = toRefs(props)
2022-04-15 14:24:30 +00:00
2024-01-08 16:59:05 +00:00
const { isPlus } = useKoelPlus()
2024-01-04 10:24:40 +00:00
const { currentUser } = useAuthorization()
const { startDragging } = useDraggable('songs')
2024-01-08 16:59:05 +00:00
const external = computed(() => isPlus.value && song.value.owner_id !== currentUser.value?.id)
2024-01-04 10:24:40 +00:00
2022-04-15 17:00:08 +00:00
const requestContextMenu = (event: MouseEvent) => eventBus.emit('SONG_CONTEXT_MENU_REQUESTED', event, song.value)
const onDragStart = (event: DragEvent) => startDragging(event, [song.value])
2022-04-15 14:24:30 +00:00
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
}
2022-04-15 14:24:30 +00:00
</script>
2024-04-04 20:13:35 +00:00
<style lang="postcss" scoped>
2022-04-15 14:24:30 +00:00
article {
&.playing {
2024-04-04 22:20:42 +00:00
@apply text-k-accent;
}
2024-04-04 20:13:35 +00:00
/* show the thumbnail's playback control on the whole card focus and hover */
2024-04-23 21:01:27 +00:00
2024-04-04 22:20:42 +00:00
&:hover :deep(.song-thumbnail), &:focus :deep(.song-thumbnail) {
2022-04-15 14:24:30 +00:00
&::before {
2024-04-04 22:20:42 +00:00
@apply opacity-70;
2022-04-15 14:24:30 +00:00
}
2022-08-03 21:01:47 +00:00
}
2022-04-15 14:24:30 +00:00
}
</style>