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

73 lines
1.9 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";
2020-04-26 11:38:54 +00:00
import { Grid, Button } from "semantic-ui-react";
2020-04-14 12:58:03 +00:00
class ScenesPanel extends Component {
constructor(props) {
super(props);
2020-04-26 11:38:54 +00:00
this.applyScene = this.applyScene.bind(this);
}
applyScene() {
console.log(this.props.activeScene);
this.props.sceneApply(this.props.activeScene);
2020-04-14 12:58:03 +00:00
}
render() {
2020-04-16 13:15:33 +00:00
return (
<Grid doubling columns={2} divided="vertically">
2020-04-26 11:38:54 +00:00
{!this.props.isActiveDefaultScene ? (
<Grid.Row centered>
<Button color="blue" onClick={this.applyScene}>
Apply Scene
</Button>
</Grid.Row>
) : null}
{!this.props.isActiveDefaultScene
? this.props.sceneStates.map((e, i) => {
return (
<Grid.Column key={i}>
2020-04-25 15:46:04 +00:00
<Device tab={this.props.tab} id={e.id} />
</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();
2020-04-27 13:20:48 +00:00
console.log("STATESCENE", stateArray);
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;