2020-03-23 21:45:13 +00:00
|
|
|
// vim: set ts=2 sw=2 et tw=80:
|
|
|
|
|
2020-03-23 20:24:17 +00:00
|
|
|
import React, { Component } from "react";
|
2020-05-01 18:05:39 +00:00
|
|
|
import { Segment, Card } from "semantic-ui-react";
|
2020-04-10 15:25:52 +00:00
|
|
|
import Device from "./devices/Device";
|
2020-03-18 14:30:02 +00:00
|
|
|
import NewDevice from "./devices/NewDevice";
|
2020-04-09 15:24:30 +00:00
|
|
|
import { connect } from "react-redux";
|
|
|
|
import { RemoteService } from "../../remote";
|
2020-03-15 14:50:25 +00:00
|
|
|
|
2020-04-09 15:24:30 +00:00
|
|
|
class DevicePanel extends Component {
|
2020-03-23 20:24:17 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2020-03-15 14:50:25 +00:00
|
|
|
|
2020-04-09 15:24:30 +00:00
|
|
|
this.getDevices();
|
2020-03-23 20:24:17 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 15:24:30 +00:00
|
|
|
getDevices() {
|
2020-04-21 12:58:36 +00:00
|
|
|
if (this.props.tab === "Devices") {
|
|
|
|
this.props
|
|
|
|
.fetchDevices()
|
|
|
|
.catch((err) => console.error(`error fetching devices:`, err));
|
|
|
|
}
|
2020-03-23 20:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2020-05-01 18:05:39 +00:00
|
|
|
<Card.Group centered style={{ paddingTop: "3rem" }}>
|
2020-04-14 12:58:03 +00:00
|
|
|
{this.props.devices.map((e, i) => {
|
2020-05-02 11:58:02 +00:00
|
|
|
return <Device key={i} tab={this.props.tab} id={e.id} />;
|
2020-04-14 12:58:03 +00:00
|
|
|
})}
|
|
|
|
{!this.props.isActiveRoomHome ? (
|
2020-05-01 18:05:39 +00:00
|
|
|
<Card style={{ height: "23em" }}>
|
|
|
|
<Segment basic style={{ width: "100%", height: "100%" }}>
|
|
|
|
<NewDevice />
|
|
|
|
</Segment>
|
|
|
|
</Card>
|
2020-04-14 12:58:03 +00:00
|
|
|
) : null}
|
2020-05-01 14:42:42 +00:00
|
|
|
</Card.Group>
|
2020-03-23 20:24:17 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-04-09 15:24:30 +00:00
|
|
|
|
|
|
|
const mapStateToProps = (state, _) => ({
|
|
|
|
get devices() {
|
|
|
|
if (state.active.activeRoom === -1) {
|
|
|
|
return Object.values(state.devices);
|
|
|
|
} else {
|
2020-04-12 15:49:29 +00:00
|
|
|
const deviceArray = [
|
|
|
|
...state.rooms[state.active.activeRoom].devices,
|
|
|
|
].sort();
|
2020-04-10 15:52:02 +00:00
|
|
|
return deviceArray.map((id) => state.devices[id]);
|
2020-04-09 15:24:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
get isActiveRoomHome() {
|
2020-04-10 15:25:52 +00:00
|
|
|
return state.active.activeRoom === -1;
|
2020-04-09 15:24:30 +00:00
|
|
|
},
|
|
|
|
activeRoom: state.active.activeRoom,
|
|
|
|
});
|
|
|
|
const DevicePanelContainer = connect(
|
|
|
|
mapStateToProps,
|
|
|
|
RemoteService
|
|
|
|
)(DevicePanel);
|
|
|
|
export default DevicePanelContainer;
|