forked from sonos/api-web-sample-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetchGroupsController.jsx
63 lines (61 loc) · 2.28 KB
/
fetchGroupsController.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
58
59
60
61
62
63
import React from "react";
import { Component } from "react";
import GetGroups from "../UserDetails/getGroups";
import ListGroupsComponent from "../Components/listGroupsComponent";
import GroupsSubscribe from "../UserDetails/groupsSubscribe";
/**
* Class component that fetches and displays list of all groups in selected household
*/
class FetchGroups extends Component {
/**
* @param props.setGroupsInfoState Modifies state of groupsInfoAtom, which contains information on groups, players, and household ID
* @param props.groupsInfoState {JSON} Accesses state of groupsInfoAtom
* @param props.householdId {string} Used to target specific household in Sonos API calls
* @param props.museClientConfig {JSON} Contains Sonos API access token
*/
constructor(props) {
super(props);
// Default value for groupFlag causes groups to be fetched on instantiation
this.props.setGroupsInfoState({
groupFlag: true,
groups: null,
players: null
});
}
render() {
return (
<div>
<div className="getHouseholdID">
{/* Upon instantiation, fetches groups information from Sonos API and sets groupFlag to false */}
{this.props.groupsInfoState.groupFlag && (
<GetGroups
householdId={this.props.householdId}
museClientConfig={this.props.museClientConfig}
setGroup={false}
showLoadingScreen={true}
/>
)}
</div>
<div>
{/*
Subscribes to groups events for the current household
Any groups change events received cause this component to be re-rendered with the new information
*/}
<GroupsSubscribe householdId= {this.props.householdId}/>
</div>
<div>
{/* Once groups information has been fetched, a button that routes user to group playback page is created for each group */}
{!this.props.groupsInfoState.groupFlag && (
<ListGroupsComponent
navigate={this.props.navigate}
groups={this.props.groupsInfoState.groups}
players={this.props.groupsInfoState.players}
householdId={this.props.householdId}
/>
)}
</div>
</div>
);
}
}
export default FetchGroups;