diff --git a/smart-hut/src/App.js b/smart-hut/src/App.js index 9810d84..b003ebe 100644 --- a/smart-hut/src/App.js +++ b/smart-hut/src/App.js @@ -31,8 +31,12 @@ class App extends Component { let userJsonString = localStorage.getItem("token"); let exp = localStorage.getItem("exp"); let date = new Date().getTime(); + console.log(exp > date, date) if (userJsonString && exp && date < exp) { loggedIn = true; + } else { + localStorage.removeItem("token"); + localStorage.removeItem("exp"); } }catch(exception) { @@ -64,8 +68,9 @@ class App extends Component { return call.login(data.params) .then(res => { if (res.data && res.status === 200) { + let expire = new Date().getTime()+60*60*5*1000; localStorage.setItem("token", res.data.jwttoken); - localStorage.setItem("exp", new Date().getTime() + (60*60*5)) + localStorage.setItem("exp", expire) call.setToken(res.data.jwttoken); this.setState( { @@ -94,6 +99,7 @@ class App extends Component { }); localStorage.removeItem("token"); + localStorage.removeItem("exp"); }; render() { diff --git a/smart-hut/src/components/dashboard/DevicePanel.js b/smart-hut/src/components/dashboard/DevicePanel.js index b4a0e7f..bca0212 100644 --- a/smart-hut/src/components/dashboard/DevicePanel.js +++ b/smart-hut/src/components/dashboard/DevicePanel.js @@ -94,6 +94,7 @@ export default class DevicePanel extends Component { console.log(roomId) data["id"] = this.state.settingsDeviceId; data["roomId"] = roomId; + console.log(data); call.deviceUpdate(data) .then(res => { if (res.status === 200) { diff --git a/smart-hut/src/components/dashboard/devices/DeviceTypeController.js b/smart-hut/src/components/dashboard/devices/DeviceTypeController.js index 9049fd6..8f21cfa 100644 --- a/smart-hut/src/components/dashboard/devices/DeviceTypeController.js +++ b/smart-hut/src/components/dashboard/devices/DeviceTypeController.js @@ -8,7 +8,7 @@ import Switcher from "./Switch"; const DeviceType = (props) => { switch(props.type) { - case "regular-light": + case "regularLight": return () case "sensor": return @@ -18,7 +18,7 @@ const DeviceType = (props) => { return case "switch": return - case "light": + case "dimmableLight": return () default: return "" diff --git a/smart-hut/src/components/dashboard/devices/Light.js b/smart-hut/src/components/dashboard/devices/Light.js index d358ab7..b2d3049 100644 --- a/smart-hut/src/components/dashboard/devices/Light.js +++ b/smart-hut/src/components/dashboard/devices/Light.js @@ -25,11 +25,17 @@ export default class Light extends Component { } onClickDevice = () => { - this.setState((prevState) => ({turnedOn: !prevState.turnedOn})); + this.props.device.on = !this.state.turnedOn; + call.deviceUpdate(this.props.device, 'regularLight') + .then(res => { + if (res.status === 200 ){ + this.setState((prevState) => ({turnedOn: !prevState.turnedOn})); + } + }) }; setIntensity = (newValue) => { - this.props.device.intensity = Math.round(newValue) <= 1 ? 1 : Math.round(newValue ); + this.props.device.intensity = Math.round(newValue * 100) <= 1 ? 1 : Math.round(newValue * 100); console.log(this.props.device.intensity) call.deviceUpdate(this.props.device, 'dimmableLight') .then(res => { @@ -52,6 +58,9 @@ export default class Light extends Component { intensity: this.props.device.intensity }); } + this.setState({ + turnedOn: this.props.device.on + }); // Get the state and update it } @@ -60,7 +69,7 @@ export default class Light extends Component { render() { const intensityLightView = ( diff --git a/smart-hut/src/components/modalform.js b/smart-hut/src/components/modalform.js index 699da5d..117a8c9 100644 --- a/smart-hut/src/components/modalform.js +++ b/smart-hut/src/components/modalform.js @@ -108,12 +108,12 @@ export default class ModalWindow extends Component {

Insert the name of the room:

+ value={this.props.type === "new" && this.props.idRoom !== -1 ? "" : "" }/>

Insert an image of the room:

+ value={this.props.type === "new" && this.props.idRoom !== -1 ? "" : this.props.idRoom.images }/> @@ -126,7 +126,7 @@ export default class ModalWindow extends Component { : null } + : "" } diff --git a/smart-hut/src/views/Dashboard.js b/smart-hut/src/views/Dashboard.js index e83e1f0..f35e947 100644 --- a/smart-hut/src/views/Dashboard.js +++ b/smart-hut/src/views/Dashboard.js @@ -36,6 +36,7 @@ export default class Dashboard extends Component{ call.getAllDevices() .then(res => { if ( res.status === 200) { + console.log(res.data) this.setState({ devices: res.data }); diff --git a/smart-hut/src/views/Navbar.js b/smart-hut/src/views/Navbar.js index 11d48e0..109fa7a 100644 --- a/smart-hut/src/views/Navbar.js +++ b/smart-hut/src/views/Navbar.js @@ -120,6 +120,7 @@ class Navbar extends Component { @@ -168,10 +169,10 @@ class Navbar extends Component { - + - +