Skip to content

Commit

Permalink
play track when TrackRow is double clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Jacquin committed Feb 12, 2019
1 parent 50564ec commit d817899
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
48 changes: 22 additions & 26 deletions app/components/TrackRow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,12 @@ class TrackRow extends React.Component {

renderPlayTrackButton (
index,
track,
clearQueue,
addToQueue,
selectSong,
startPlayback,
musicSources
) {
return (
<a
key={'play-track-' + index}
href='#'
onClick={() => {
clearQueue();
addToQueue(musicSources, {
artist: track.artist.name,
name: track.name,
thumbnail: _.get(track, 'image[0][\'#text\']', artPlaceholder)
});
selectSong(0);
startPlayback();
}}
onClick={this.playTrack}
className={styles.add_button}
aria-label='Play this track now'
>
Expand All @@ -61,6 +46,26 @@ class TrackRow extends React.Component {
);
}

playTrack = () => {
const {
track,
clearQueue,
addToQueue,
selectSong,
startPlayback,
musicSources
} = this.props;

clearQueue();
addToQueue(musicSources, {
artist: track.artist.name,
name: track.name,
thumbnail: _.get(track, 'image[0][\'#text\']', artPlaceholder)
});
selectSong(0);
startPlayback();
}

renderDuration (track) {
if (track.duration === 0) {
return <td className={styles.track_duration} />;
Expand All @@ -74,7 +79,7 @@ class TrackRow extends React.Component {

renderTrigger (track) {
return (
<tr className={styles.track}>
<tr className={styles.track} onDoubleClick={this.playTrack}>
{this.props.displayCover ? <td
style={{
backgroundImage: `url(${_.get(track, 'image[0][#text]', artPlaceholder)})`,
Expand All @@ -95,10 +100,7 @@ class TrackRow extends React.Component {
let {
index,
track,
clearQueue,
addToQueue,
selectSong,
startPlayback,
musicSources
} = this.props;

Expand All @@ -111,12 +113,6 @@ class TrackRow extends React.Component {
),
this.renderPlayTrackButton(
index,
track,
clearQueue,
addToQueue,
selectSong,
startPlayback,
musicSources
)
];
return (
Expand Down
1 change: 1 addition & 0 deletions app/components/TrackRow/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

.track {
transition: $short-duration;
cursor: pointer;
}

.track_thumbnail {
Expand Down

0 comments on commit d817899

Please sign in to comment.