-
Notifications
You must be signed in to change notification settings - Fork 6
/
playlistsController.jsx
57 lines (51 loc) · 1.93 KB
/
playlistsController.jsx
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
import React from "react";
import { Component } from "react";
import GetPlaylists from "../UserDetails/getPlaylists";
import PlaylistComponent from "../Components/playlistComponent";
/**
* Class component that fetches and displays list of all Sonos playlists in selected household
*/
class PlaylistsController extends Component {
/**
* @param props.museClientConfig {JSON} Contains Sonos API access token and configuration
* @param props.householdId {string} Used to target current household when fetching playlists
* @param props.groupId {string} Used to target current group when loading playlists
*/
constructor(props) {
super(props);
// fetchFlag = true causes playlists to be fetched on instantiation
this.state = {fetchFlag: true, playlists: []};
}
/**
* Handler function that updates the array of playlists in this.state
* @param playlists {Array} Array of JSON objects each containing the information of a playlist in current household
*/
playlistsHandler = (playlists) => {
// Fetch flag = false stops fetching of playlists from Sonos API
this.setState({fetchFlag: false, playlists:playlists});
}
render() {
return (
<div className="favorites_list">
{/* Upon instantiation, fetches playlists from Sonos API and sets fetchFlag to false */}
{this.state.fetchFlag && (
<GetPlaylists
museClientConfig={this.props.museClientConfig}
householdId={this.props.householdId}
playlistsHandler={this.playlistsHandler}
/>)}
{/* Once playlists have been fetched, a button is created for each playlist */}
{!this.state.fetchFlag && (
this.state.playlists.map((item) => {
return (<PlaylistComponent
key={item.id}
state={item}
groupId={this.props.groupId}
/>)
})
)}
</div>
);
}
}
export default PlaylistsController;