koel/resources/assets/js/components/shared/song-item.vue

135 lines
3.4 KiB
Vue
Raw Normal View History

2015-12-13 04:42:28 +00:00
<template>
<tr
2016-01-07 08:11:11 +00:00
@dblclick.prevent="playRighAwayyyyyyy"
2015-12-13 04:42:28 +00:00
class="song-item"
2016-01-16 18:11:24 +00:00
:class="{ selected: selected, playing: playbackState === 'playing' || playbackState === 'paused' }"
2015-12-13 04:42:28 +00:00
>
<td class="title">{{ song.title }}</td>
<td class="artist">{{ song.album.artist.name }}</td>
<td class="album">{{ song.album.name }}</td>
<td class="time">{{ song.fmtLength }}</td>
<td class="play" @click.stop="doPlayback">
<i class="fa fa-pause-circle" v-show="playbackState === 'playing'"></i>
<i class="fa fa-play-circle" v-else></i>
2016-01-07 04:22:02 +00:00
</td>
2015-12-13 04:42:28 +00:00
</tr>
</template>
<script>
2016-01-06 16:41:59 +00:00
import $ from 'jquery';
2015-12-13 04:42:28 +00:00
import playback from '../../services/playback';
2016-01-07 08:11:11 +00:00
import queueStore from '../../stores/queue';
2015-12-13 04:42:28 +00:00
export default {
props: ['song'],
data() {
return {
2016-01-07 04:22:02 +00:00
playbackState: 'stopped',
selected: false,
2015-12-13 04:42:28 +00:00
};
},
methods: {
/**
2016-01-07 08:11:11 +00:00
* Play the song right away.
2015-12-13 04:42:28 +00:00
*/
2016-01-07 08:11:11 +00:00
playRighAwayyyyyyy() {
if (!queueStore.contains(this.song)) {
queueStore.queueAfterCurrent(this.song);
}
Vue.nextTick(() => playback.play(this.song));
2015-12-13 04:42:28 +00:00
},
2016-01-06 16:41:59 +00:00
/**
* Take the right playback action based on the current playback state.
*/
doPlayback() {
switch (this.playbackState) {
case 'playing':
playback.pause();
break;
case 'paused':
playback.resume();
break;
default:
this.playRighAwayyyyyyy();
break;
}
2016-01-06 16:41:59 +00:00
},
/**
* Toggle the "selected" state of the current component.
*/
toggleSelectedState() {
this.selected = !this.selected;
},
select() {
this.selected = true;
},
deselect() {
this.selected = false;
}
2015-12-13 04:42:28 +00:00
},
events: {
// Listen to playback events and set playback state.
2016-01-07 04:22:02 +00:00
2016-01-07 09:03:38 +00:00
'song:played': function (song) {
2016-01-07 04:22:02 +00:00
this.playbackState = this.song.id === song.id ? 'playing' : 'stopped';
},
2016-01-07 09:03:38 +00:00
'song:stopped': function () {
2016-01-07 04:22:02 +00:00
this.playbackState = 'stopped';
},
2015-12-13 04:42:28 +00:00
2016-01-07 09:03:38 +00:00
'song:paused': function (song) {
2016-01-07 04:22:02 +00:00
if (this.song.id === song.id) {
this.playbackState = 'paused';
}
2015-12-13 04:42:28 +00:00
},
},
};
</script>
<style lang="sass">
@import "resources/assets/sass/partials/_vars.scss";
@import "resources/assets/sass/partials/_mixins.scss";
.song-item {
border-bottom: 1px solid $color2ndBgr;
2016-01-07 04:22:02 +00:00
html.no-touchevents &:hover {
2015-12-13 04:42:28 +00:00
background: rgba(255, 255, 255, .05);
}
.time {
color: $color2ndText;
}
.title {
min-width: 192px;
}
2016-01-07 04:22:02 +00:00
.play {
2016-01-06 16:41:59 +00:00
max-width: 32px;
2016-01-07 04:22:02 +00:00
opacity: .5;
i {
font-size: 150%;
}
2016-01-06 16:41:59 +00:00
}
2015-12-13 04:42:28 +00:00
&.selected {
background-color: rgba(255, 255, 255, .08);
}
&.playing {
color: $colorHighlight;
}
}
</style>