2020-04-15 13:54:30 +00:00
|
|
|
import React, { Component } from "react";
|
|
|
|
import {
|
|
|
|
Menu,
|
|
|
|
Button,
|
|
|
|
Icon,
|
2020-04-18 14:26:12 +00:00
|
|
|
Grid,
|
2020-04-15 13:54:30 +00:00
|
|
|
Responsive,
|
|
|
|
Dropdown,
|
|
|
|
} from "semantic-ui-react";
|
|
|
|
import { editButtonStyle } from "../components/dashboard/devices/styleComponents";
|
|
|
|
import SceneModal from "../components/SceneModal";
|
|
|
|
import { RemoteService } from "../remote";
|
|
|
|
import { connect } from "react-redux";
|
|
|
|
import { appActions } from "../storeActions";
|
|
|
|
|
|
|
|
class ScenesNavbar extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
editMode: false,
|
|
|
|
};
|
|
|
|
this.toggleEditMode = this.toggleEditMode.bind(this);
|
|
|
|
this.openCurrentModalMobile = this.openCurrentModalMobile.bind(this);
|
2020-04-18 14:26:12 +00:00
|
|
|
this.selectScene = this.selectScene.bind(this);
|
|
|
|
|
|
|
|
this.getScenes();
|
2020-04-15 13:54:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get activeItemScene() {
|
|
|
|
return this.props.activeScene;
|
|
|
|
}
|
|
|
|
|
|
|
|
set activeItemScene(item) {
|
|
|
|
this.props.setActiveScene(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
get activeItemSceneName() {
|
2020-04-18 14:26:12 +00:00
|
|
|
if (this.props.activeScene === -1) return "Scene";
|
2020-04-15 13:54:30 +00:00
|
|
|
return this.props.scenes[this.props.activeScene].name;
|
|
|
|
}
|
|
|
|
|
2020-04-18 14:26:12 +00:00
|
|
|
getScenes() {
|
2020-04-21 12:58:36 +00:00
|
|
|
this.props.fetchAllScenes().catch(console.error);
|
2020-04-18 14:26:12 +00:00
|
|
|
}
|
|
|
|
|
2020-04-15 13:54:30 +00:00
|
|
|
openCurrentModalMobile() {
|
2020-04-21 12:58:36 +00:00
|
|
|
//console.log(this.activeItemScene, this.props.sceneModalRefs);
|
2020-04-18 14:26:12 +00:00
|
|
|
const currentModal = this.props.sceneModalRefs[this.activeItemScene]
|
|
|
|
.current;
|
2020-04-15 13:54:30 +00:00
|
|
|
currentModal.openModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleEditMode(e) {
|
|
|
|
this.setState((prevState) => ({ editMode: !prevState.editMode }));
|
|
|
|
}
|
|
|
|
|
2020-04-18 14:26:12 +00:00
|
|
|
selectScene(e, { id }) {
|
|
|
|
this.activeItemScene = id || -1;
|
2020-04-21 12:58:36 +00:00
|
|
|
this.getStates(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
getStates(sceneId) {
|
|
|
|
if (sceneId) {
|
|
|
|
this.props
|
|
|
|
.fetchStates(sceneId)
|
|
|
|
.catch((err) => console.error(`error fetching states:`, err));
|
|
|
|
}
|
2020-04-18 14:26:12 +00:00
|
|
|
}
|
|
|
|
|
2020-04-15 13:54:30 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div style={{ background: "#1b1c1d!important", padding: "0 20px" }}>
|
|
|
|
<Responsive minWidth={768}>
|
|
|
|
<Grid>
|
|
|
|
<Grid.Row color="black">
|
|
|
|
<button style={editButtonStyle} onClick={this.toggleEditMode}>
|
|
|
|
Edit
|
|
|
|
</button>
|
|
|
|
</Grid.Row>
|
|
|
|
<Grid.Row>
|
|
|
|
<Menu inverted fluid vertical>
|
|
|
|
<Menu.Item
|
|
|
|
key={-1}
|
|
|
|
id={null}
|
|
|
|
name="scene"
|
|
|
|
active={this.activeItemScene === -1}
|
|
|
|
onClick={this.selectScene}
|
|
|
|
>
|
2020-04-18 14:26:12 +00:00
|
|
|
SCENES
|
2020-04-15 13:54:30 +00:00
|
|
|
</Menu.Item>
|
2020-04-18 14:26:12 +00:00
|
|
|
|
|
|
|
{Object.values(this.props.scenes).map((e, i) => {
|
|
|
|
return (
|
|
|
|
<Menu.Item
|
|
|
|
id={e.id}
|
|
|
|
key={i}
|
|
|
|
name={e.name}
|
|
|
|
active={this.activeItemScene === e.id}
|
|
|
|
onClick={this.selectScene}
|
|
|
|
>
|
|
|
|
<Grid>
|
|
|
|
<Grid.Row>
|
|
|
|
<Grid.Column width={12}>{e.name}</Grid.Column>
|
|
|
|
<Grid.Column floated="right">
|
|
|
|
{this.state.editMode ? (
|
|
|
|
<SceneModal id={e.id} />
|
|
|
|
) : null}
|
|
|
|
</Grid.Column>
|
|
|
|
</Grid.Row>
|
|
|
|
</Grid>
|
|
|
|
</Menu.Item>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
|
2020-04-15 13:54:30 +00:00
|
|
|
<Menu.Item name="newM">
|
|
|
|
<Grid>
|
|
|
|
<Grid.Row centered name="new">
|
|
|
|
<SceneModal id={null} />
|
|
|
|
</Grid.Row>
|
|
|
|
</Grid>
|
|
|
|
</Menu.Item>
|
|
|
|
</Menu>
|
|
|
|
</Grid.Row>
|
|
|
|
</Grid>
|
|
|
|
</Responsive>
|
|
|
|
|
|
|
|
<Responsive maxWidth={768}>
|
|
|
|
<Menu>
|
|
|
|
<Dropdown item fluid text={this.activeItemSceneName}>
|
|
|
|
<Dropdown.Menu>
|
|
|
|
<Dropdown.Item
|
|
|
|
key={-1}
|
|
|
|
id={null}
|
|
|
|
name="scene"
|
|
|
|
active={this.activeItemScene === -1}
|
|
|
|
onClick={this.selectScene}
|
|
|
|
>
|
|
|
|
<Grid>
|
|
|
|
<Grid.Row>
|
|
|
|
<Grid.Column>Scene</Grid.Column>
|
|
|
|
</Grid.Row>
|
|
|
|
</Grid>
|
|
|
|
</Dropdown.Item>
|
|
|
|
|
2020-04-18 14:26:12 +00:00
|
|
|
{Object.values(this.props.scenes).map((e, i) => {
|
|
|
|
return (
|
|
|
|
<Dropdown.Item
|
|
|
|
id={e.id}
|
|
|
|
key={i}
|
|
|
|
name={e.name}
|
|
|
|
active={this.activeItemScene === e.id}
|
|
|
|
onClick={this.selectScene}
|
|
|
|
>
|
|
|
|
<Grid>
|
|
|
|
<Grid.Row>
|
|
|
|
<Grid.Column>{e.name}</Grid.Column>
|
|
|
|
</Grid.Row>
|
|
|
|
</Grid>
|
|
|
|
<SceneModal
|
|
|
|
ref={this.props.sceneModalRefs[e.id]}
|
|
|
|
nicolaStop={true}
|
|
|
|
id={e.id}
|
|
|
|
/>
|
|
|
|
</Dropdown.Item>
|
|
|
|
);
|
|
|
|
})}
|
2020-04-15 13:54:30 +00:00
|
|
|
</Dropdown.Menu>
|
|
|
|
</Dropdown>
|
|
|
|
</Menu>
|
|
|
|
<Grid inverted>
|
|
|
|
<Grid.Row>
|
|
|
|
<Grid.Column width={8}>
|
|
|
|
<SceneModal id={null} />
|
|
|
|
</Grid.Column>
|
|
|
|
{this.activeItemScene !== -1 ? (
|
|
|
|
<Grid.Column width={8}>
|
|
|
|
<Button
|
|
|
|
icon
|
|
|
|
fluid
|
|
|
|
labelPosition="left"
|
|
|
|
onClick={this.openCurrentModalMobile}
|
|
|
|
>
|
|
|
|
<Icon name="pencil" size="small" />
|
2020-04-18 14:26:12 +00:00
|
|
|
EDIT SCENE
|
2020-04-15 13:54:30 +00:00
|
|
|
</Button>
|
|
|
|
</Grid.Column>
|
|
|
|
) : null}
|
|
|
|
</Grid.Row>
|
|
|
|
</Grid>
|
|
|
|
</Responsive>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const setActiveScene = (activeScene) => {
|
|
|
|
return (dispatch) => dispatch(appActions.setActiveScene(activeScene));
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapStateToProps = (state, _) => ({
|
|
|
|
scenes: state.scenes,
|
|
|
|
sceneModalRefs: Object.keys(state.scenes).reduce(
|
|
|
|
(acc, key) => ({ ...acc, [key]: React.createRef() }),
|
|
|
|
{}
|
|
|
|
),
|
2020-04-21 12:58:36 +00:00
|
|
|
get isActiveDefaultScene() {
|
|
|
|
return state.active.activeScene === -1;
|
|
|
|
},
|
|
|
|
activeScene: state.active.activeScene,
|
2020-04-15 13:54:30 +00:00
|
|
|
});
|
|
|
|
const ScenesNavbarContainer = connect(mapStateToProps, {
|
|
|
|
...RemoteService,
|
|
|
|
setActiveScene,
|
|
|
|
})(ScenesNavbar);
|
|
|
|
export default ScenesNavbarContainer;
|