import React, { Component } from 'react'; import { connect } from 'react-redux'; import { Card, Segment, Header, Icon, Button, } from 'semantic-ui-react'; import { RemoteService } from '../../remote'; import Device from './devices/Device'; class HostsPanel extends Component { componentDidUpdate(oldProps) { if ( oldProps.activeHost !== this.props.activeHost && this.props.activeHost !== -1 ) { this.props.fetchDevices(null, this.props.activeHost).catch(console.error); this.props.fetchAllRooms(this.props.activeHost).catch(console.error); this.props.fetchAllScenes(this.props.activeHost).catch(console.error); } } applyHostScene(id) { this.props .sceneApply(id, this.props.activeHost) .then(() => console.log('SCCUESS')) .catch((err) => console.error('sceneApply update error', err)); } render() { if (this.props.isActiveDefaultHost) { return (
Please select a host to visit on the left.
); } return ( <>
Scenes
{this.props.hostScenes.map((scene) => (
{scene.name} {' '}
))}
Devices
{this.props.hostDeviceIds.map((id) => ( ))} ); } } const mapStateToProps = (state, _) => ({ isActiveDefaultHost: state.active.activeHost === -1, activeHost: state.active.activeHost, hostScenes: state.hostScenes[state.active.activeHost] || [], hostDevices: state.hostDevices, hostDeviceIds: Object.keys(state.hostDevices[state.active.activeHost] || {}), }); const HostsPanelContainer = connect(mapStateToProps, RemoteService)(HostsPanel); export default HostsPanelContainer;