import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import { Link, hashHistory } from 'react-router' import FontAwesome from 'react-fontawesome' import ArtistSentence from './ArtistSentence' import VolumeControl from './VolumeControl' import * as helpers from '../helpers' import * as coreActions from '../services/core/actions' import * as uiActions from '../services/ui/actions' import * as pusherActions from '../services/pusher/actions' class Snapcast extends React.Component{ constructor(props){ super(props); this.state = { editing_client: null } } componentDidMount(){ if (this.props.pusher_connected && this.props.snapcast_enabled){ this.props.pusherActions.getSnapcast(); } } componentWillReceiveProps(newProps){ // Just connected if (!this.props.pusher_connected && newProps.pusher_connected){ this.props.pusherActions.getSnapcast(); // Just enabled (well, identified as being enabled) } else if (!this.props.pusher_enabled && newProps.pusher_enabled && newProps.pusher_connected){ this.props.pusherActions.getSnapcast(); } } saveEditingClient(){ this.props.pusherActions.setSnapcastClientName(this.state.editing_client.id, this.state.editing_client.name); this.setState({editing_client: null}); } render(){ if (!this.props.snapcast_clients || !this.props.snapcast_groups){ return null; } // Construct a simple array of our groups index var groups = []; for (var group_id in this.props.snapcast_groups){ if (this.props.snapcast_groups.hasOwnProperty(group_id)){ var group = this.props.snapcast_groups[group_id]; // Merge the group's clients into this group (also as a simple array) var clients = []; for (var i = 0; i < group.clients_ids.length; i++){ if (this.props.snapcast_clients.hasOwnProperty(group.clients_ids[i])){ clients.push(this.props.snapcast_clients[group.clients_ids[i]]); } } groups.push(Object.assign( {}, group, { clients: clients } )); } } return (