-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrack.js
63 lines (58 loc) · 2.19 KB
/
Track.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React from 'react';
import './Track.css';
export class Track extends React.Component {
constructor(props) {
super(props);
this.addTrack = this.addTrack.bind(this);
this.removeTrack = this.removeTrack.bind(this);
this.trackUp = this.trackUp.bind(this);
this.trackDown = this.trackDown.bind(this);
}
// display add/remove button
renderAction() {
return (
!this.props.isRemoval ?
<button className="Track-action" onClick={this.addTrack}> + </button> :
this.props.isFirstTrack ?
<>
<button className="Track-action" onClick={this.trackDown}>↓</button>
<button className="Track-action" onClick={this.removeTrack}> - </button>
</> :
this.props.isLastTrack ?
<>
<button className="Track-action" onClick={this.trackUp}>↑</button><button className="Track-action" onClick={this.removeTrack}> - </button>
</> :
<>
<button className="Track-action" onClick={this.trackUp}>↑</button>
<button className="Track-action" onClick={this.trackDown}>↓</button>
<button className="Track-action" onClick={this.removeTrack}> - </button>
</>
)
}
// add this.props.track to the playlist.
addTrack() {
this.props.onAdd(this.props.track);
}
// remove this.props.track from the playlist.
removeTrack() {
this.props.onRemove(this.props.track);
}
// move track handlers
trackUp() {
this.props.onMoveUp(this.props.track);
}
trackDown() {
this.props.onMoveDown(this.props.track);
}
render() {
return (
<div className="Track">
<div className="Track-information">
<h3>{this.props.track.name}</h3>
<p>{this.props.track.artist} | {this.props.track.album}</p>
</div>
{this.renderAction()}
</div>
);
}
}