koel/resources/assets/js/components/album/AlbumTrackListItem.vue

50 lines
1.4 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<li :class="{ available: song }" :title="tooltip" tabindex="0" @click="play">
2022-04-15 14:24:30 +00:00
<span class="title">{{ track.title }}</span>
<AppleMusicButton v-if="useAppleMusic && !song" :url="iTunesUrl"/>
2022-04-15 14:24:30 +00:00
<span class="length">{{ track.fmtLength }}</span>
</li>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
import { computed, defineAsyncComponent, toRefs } from 'vue'
import { queueStore, songStore } from '@/stores'
2022-04-24 08:50:45 +00:00
import { authService, playbackService } from '@/services'
import { useThirdPartyServices } from '@/composables'
2022-04-15 14:24:30 +00:00
const AppleMusicButton = defineAsyncComponent(() => import('@/components/ui/AppleMusicButton.vue'))
2022-04-21 10:43:10 +00:00
const props = defineProps<{ album: Album, track: AlbumTrack }>()
const { album, track } = toRefs(props)
2022-04-15 14:24:30 +00:00
const { useAppleMusic } = useThirdPartyServices()
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const song = computed(() => songStore.guess(track.value.title, album.value))
const tooltip = computed(() => song.value ? 'Click to play' : '')
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const iTunesUrl = computed(() => {
2022-04-24 08:50:45 +00:00
return `${window.BASE_URL}itunes/song/${album.value.id}?q=${encodeURIComponent(track.value.title)}&api_token=${authService.getToken()}`
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 play = () => {
if (song.value) {
queueStore.queueIfNotQueued(song.value)
2022-04-24 08:50:45 +00:00
playbackService.play(song.value)
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>
li {
span.title {
margin-right: 5px;
}
2022-04-15 14:24:30 +00:00
&:focus {
span.title {
color: var(--color-highlight);
}
}
}
</style>