frontend/smart-hut/src/components/dashboard/ScenesPanel.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-04-14 12:58:03 +00:00
import React, { Component } from "react";
import { connect } from "react-redux";
import { RemoteService } from "../../remote";
import Device from "./devices/Device";
2020-04-16 13:15:33 +00:00
import NewSceneDevice from "./NewSceneDevice";
import { Grid } from "semantic-ui-react";
2020-04-14 12:58:03 +00:00
class ScenesPanel extends Component {
constructor(props) {
super(props);
}
render() {
2020-04-16 13:15:33 +00:00
return (
<Grid doubling columns={2} divided="vertically">
{!this.props.isActiveDefaultScene
? this.props.sceneStates.map((e, i) => {
return (
<Grid.Column key={i}>
<Device tab={this.props.tab} id={e} />
</Grid.Column>
);
})
: null}
{!this.props.isActiveDefaultScene ? (
2020-04-16 13:15:33 +00:00
<Grid.Column>
<NewSceneDevice />
</Grid.Column>
) : (
<Grid.Column>Welcome to the Scene View, you add a Scene</Grid.Column>
)}
2020-04-16 13:15:33 +00:00
</Grid>
);
2020-04-14 12:58:03 +00:00
}
}
const mapStateToProps = (state, _) => ({
get sceneStates() {
if (state.active.activeScene !== -1) {
const stateArray = [
...state.scenes[state.active.activeScene].sceneStates,
].sort();
return stateArray.map((id) => state.sceneStates[id]);
} else {
return [];
}
},
2020-04-16 13:15:33 +00:00
get isActiveDefaultScene() {
return state.active.activeScene === -1;
},
activeScene: state.active.activeScene,
2020-04-14 12:58:03 +00:00
});
const ScenesPanelContainer = connect(
mapStateToProps,
RemoteService
)(ScenesPanel);
export default ScenesPanelContainer;