diff --git a/smart-hut/src/components/SceneModal.js b/smart-hut/src/components/SceneModal.js index cff8630..4f4901d 100644 --- a/smart-hut/src/components/SceneModal.js +++ b/smart-hut/src/components/SceneModal.js @@ -7,7 +7,6 @@ import { Responsive, Form, Input, - Dropdown, } from "semantic-ui-react"; import { connect } from "react-redux"; import { RemoteService } from "../remote"; @@ -19,7 +18,6 @@ class SceneModal extends Component { super(props); this.state = this.initialState; this.setInitialState(); - this.getDevices(); this.addSceneModal = this.addSceneModal.bind(this); this.modifySceneModal = this.modifySceneModal.bind(this); @@ -29,7 +27,6 @@ class SceneModal extends Component { get initialState() { return { name: this.type === "new" ? "New Scene" : this.props.room.name, - sceneDevices: this.type === "new" ? [{}] : [this.props.scene.devices], openModal: false, }; } @@ -42,12 +39,6 @@ class SceneModal extends Component { return !this.props.id ? "new" : "modify"; } - getDevices() { - this.props - .fetchDevices() - .catch((err) => console.error(`error fetching devices:`, err)); - } - addSceneModal = (e) => { /*let data = { // DATA HERE @@ -99,21 +90,7 @@ class SceneModal extends Component { this.setState({ openModal: true }); }; - setSceneDevice(e, d) { - this.setState({ sceneDevices: d.value }); - } - render() { - const availableDevices = []; - this.props.devices.forEach((e) => { - if (!this.state.sceneDevices.includes(e)) { - availableDevices.push({ - key: e.id, - text: e.name, - id: e.id, - }); - } - }); return (
{!this.props.nicolaStop ? ( @@ -176,17 +153,6 @@ class SceneModal extends Component { value={this.state.name} /> - - - - {this.type === "modify" ? ( @@ -229,16 +195,6 @@ const setActiveScene = (activeScene) => { }; const mapStateToProps = (state, ownProps) => ({ - get devices() { - if (state.active.activeRoom === -1) { - return Object.values(state.devices); - } else { - const deviceArray = [ - ...state.rooms[state.active.activeRoom].devices, - ].sort(); - return deviceArray.map((id) => state.devices[id]); - } - }, scene: ownProps.id ? state.scenes[ownProps.id] : null, }); const SceneModalContainer = connect( diff --git a/smart-hut/src/components/dashboard/NewSceneDevice.js b/smart-hut/src/components/dashboard/NewSceneDevice.js index 0a37af2..affacb5 100644 --- a/smart-hut/src/components/dashboard/NewSceneDevice.js +++ b/smart-hut/src/components/dashboard/NewSceneDevice.js @@ -1,5 +1,5 @@ import React, { Component } from "react"; -import { Button, Modal, Icon, Image } from "semantic-ui-react"; +import { Button, Modal, Icon, Image, Form, Dropdown } from "semantic-ui-react"; import { connect } from "react-redux"; import { RemoteService } from "../../remote"; import styled from "styled-components"; @@ -30,7 +30,18 @@ class NewSceneDevice extends Component { this.state = { openModal: false, + sceneDevices: this.props.scene ? this.props.scene.devices : {}, + deviceName: "", }; + this.getDevices(); + + this.setSceneDevice = this.setSceneDevice.bind(this); + } + + getDevices() { + this.props + .fetchDevices() + .catch((err) => console.error(`error fetching devices:`, err)); } handleOpen = () => { @@ -45,7 +56,21 @@ class NewSceneDevice extends Component { this.handleClose(); }; + setSceneDevice(e, d) { + this.setState({ devicesAttached: d.value }); + } + render() { + const availableDevices = []; + this.props.devices.forEach((e) => { + if (!Object.keys(this.state.sceneDevices).find((d) => e.id === d)) { + availableDevices.push({ + key: e.id, + text: e.name, + value: e.id, + }); + } + }); return ( Add a New Scene Device - + +
+ + + + +
+