forked from AdaGold/radio-lovelace
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathRadioSet.js
122 lines (83 loc) · 2.98 KB
/
RadioSet.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import React, { Component } from 'react';
import "./styles/RadioSet.css";
import PropTypes from 'prop-types'
import Playlist from './Playlist';
class RadioSet extends Component {
constructor(props) {
super();
this.state = {
morningTracks: props.tracks.slice(0, props.tracks.length / 2),
eveningTracks: props.tracks.slice(props.tracks.length / 2, props.tracks.length)
}
}
radioTopLeft =(index)=>{
let updatedMorningTracks = this.state.morningTracks;
let temp = updatedMorningTracks.splice(index,1)[0];
updatedMorningTracks.unshift(temp);
this.setState({morningTracks: updatedMorningTracks});
};
radioTopRight =(index)=>{
let updatedEveningTracks = this.state.eveningTracks;
let temp = updatedEveningTracks.splice(index,1)[0];
updatedEveningTracks.unshift(temp);
this.setState({eveningTracks: updatedEveningTracks});
};
radioSwitchRight =(index)=>{
let updatedMorningTracks = this.state.morningTracks;
let updatedEveningTracks = this.state.eveningTracks;
let temp = updatedMorningTracks.splice(index,1)[0];
updatedEveningTracks.unshift(temp);
this.setState({morningTracks: updatedMorningTracks, eveningTracks: updatedEveningTracks});
};
radioSwitchLeft =(index)=>{
let updatedMorningTracks = this.state.morningTracks;
let updatedEveningTracks = this.state.eveningTracks;
let temp = updatedEveningTracks.splice(index,1)[0];
updatedMorningTracks.unshift(temp);
this.setState({morningTracks: updatedMorningTracks, eveningTracks: updatedEveningTracks});
};
radioFavoriteLeft =(index)=>{
const newState = {...this.state};
const playlistTracks = [...newState["morningTracks"]];
const track = {...playlistTracks[index]};
track.favorite = !track.favorite;
playlistTracks[index] = track;
newState["morningTracks"] = playlistTracks;
this.setState(newState);
};
radioFavoriteRight =(index)=>{
const newState = {...this.state};
const playlistTracks = [...newState["eveningTracks"]];
const track = {...playlistTracks[index]};
track.favorite = !track.favorite;
playlistTracks[index] = track;
newState["eveningTracks"] = playlistTracks;
this.setState(newState);
};
render() {
return (
<div className="radio-set">
<section className="radio-set--playlist-container">
<Playlist
side="Morning"
tracks={this.state.morningTracks}
topCallback={this.radioTopLeft}
radioSwitchCallback={this.radioSwitchRight}
radioFavoriteCallback={this.radioFavoriteLeft}
/>
<Playlist
side="Evening"
tracks={this.state.eveningTracks}
topCallback={this.radioTopRight}
radioSwitchCallback={this.radioSwitchLeft}
radioFavoriteCallback={this.radioFavoriteRight}
/>
</section>
</div>
);
}
};
RadioSet.propTypes = {
tracks: PropTypes.array,
}
export default RadioSet;