// vim: set ts=2 sw=2 et tw=80: import React, { Component } from 'react'; import { Segment, Card, Header, Icon, } from 'semantic-ui-react'; import { connect } from 'react-redux'; import Device from './devices/Device'; import NewDevice from './devices/NewDevice'; import { RemoteService } from '../../remote'; class DevicePanel extends Component { constructor(props) { super(props); this.getDevices(); } getDevices() { if (this.props.tab === 'Devices') { this.props .fetchDevices() .catch((err) => console.error('error fetching devices:', err)); } } render() { return ( {this.props.numbeOfRooms > 0 ? ( <> {this.props.devices.map((e, i) => )} {!this.props.isActiveRoomHome ? ( ) : null} ) : (
Please create a room on the left, and then add devices to the same.
)}
); } } const mapStateToProps = (state, _) => ({ get devices() { if (state.active.activeRoom === -1) { return Object.values(state.devices); } const deviceArray = [ ...state.rooms[state.active.activeRoom].devices, ].sort(); return deviceArray.map((id) => state.devices[id]); }, get isActiveRoomHome() { return state.active.activeRoom === -1; }, activeRoom: state.active.activeRoom, get numbeOfRooms() { return Object.keys(state.rooms).length; }, }); const DevicePanelContainer = connect( mapStateToProps, RemoteService, )(DevicePanel); export default DevicePanelContainer;