moved everyting in the right files, ready to work on the backend part.

This commit is contained in:
Fil Cesana 2020-04-22 13:34:10 +02:00
parent 509335a061
commit 840d5ab6a2
7 changed files with 183 additions and 248 deletions

View file

@ -10,61 +10,132 @@
import React, { Component } from "react";
import {
StyledDiv
} from "./VideocmStyle";
import { Checkbox, Embed, Button, Grid, Responsive, Segment } from "semantic-ui-react";
iconStyle,
StyledDiv,
BottomPanel,
ThumbText,
} from "./styleComponents";
import { Image } from "semantic-ui-react";
import {
CircularInput,
CircularProgress,
CircularThumb,
} from "react-circular-input";
import {
LightDimmerContainer,
LightDimmerStyle,
textStyle,
nameStyle,
KnobProgress,
CircularThumbStyle,
knobIcon,
} from "./LightStyle";
import { RemoteService } from "../../../remote";
import { connect } from "react-redux";
import VideocamModal from "./VideocamModal";
class Light extends Component {
constructor(props) {
super(props);
this.state = { selectedVideo: undefined};
this.state = { intensity: this.props.device.intensity, timeout: null };
this.iconOn = "/img/lightOn.svg";
this.iconOff = "/img/lightOff.svg";
this.setIntensity = this.setIntensity.bind(this);
}
openModal = () => {
this.setState((state) => {
return {selectedVideo: true}
get turnedOn() {
return this.props.device.on;
}
});
get intensity() {
return this.props.device.intensity || 0;
}
onClickDevice = () => {
const on = !this.turnedOn;
this.props
.saveDevice({ ...this.props.device, on })
.catch((err) => console.error("regular light update error", err));
};
closeModal = () => {
this.setState((state) => {
return {selectedVideo:undefined}
})
getIcon = () => {
return this.turnedOn ? this.iconOn : this.iconOff;
};
setIntensity(intensity) {
intensity *= 100;
if (this.state.timeout) {
clearTimeout(this.state.timeout);
}
this.setState({
intensity,
timeout: setTimeout(() => {
this.saveIntensity();
this.setState({
intensity: this.state.intensity,
timeout: null,
});
}, 100),
});
}
saveIntensity = () => {
const intensity = Math.round(this.state.intensity);
this.props
.saveDevice({ ...this.props.device, intensity })
.catch((err) => console.error("intensity light update error", err));
};
render() {
const intensityLightView = (
<div style={LightDimmerContainer}>
<CircularInput
style={LightDimmerStyle}
value={+(Math.round(this.state.intensity / 100 + "e+2") + "e-2")}
onChange={this.setIntensity}
onMouseUp={this.saveIntensity}
>
<text
style={textStyle}
x={100}
y={120}
textAnchor="middle"
dy="0.3em"
fontWeight="bold"
>
Intensity light
</text>
<CircularProgress
style={{
...KnobProgress,
opacity: this.state.intensity / 100 + 0.3,
}}
/>
<CircularThumb style={CircularThumbStyle} />
<ThumbText color={"#ffd31d"} />
</CircularInput>
<Image style={knobIcon} src="/img/intensityLightIcon.svg" />
</div>
);
const normalLightView = (
<div>
<StyledDiv>
<div onClick={this.openModal}>
<video autoPlay loop muted width= "100%" height="auto">
<source src="paranormal-activity.mp4" type='video/mp4' />
</video>
</div>
</StyledDiv>
<Grid columns="equal" divide padded>
<Grid.Row textAlign="center">
<Grid.Column>
<VideocamModal
selectedVideo = {this.state.selectedVideo}
closeModal = {this.closeModal}
/>
</Grid.Column>
</ Grid.Row>
</Grid>
</div>
<StyledDiv>
<div onClick={this.onClickDevice}>
<Image src={this.getIcon()} style={iconStyle} />
<BottomPanel style={{ backgroundColor: "#ffa41b" }}>
<h5 style={nameStyle}>Light</h5>
</BottomPanel>
</div>
</StyledDiv>
);
return (
<div>
{this.props.device.kind === "dimmableLight"
? console.log('err')
? intensityLightView
: normalLightView}
</div>
);

View file

@ -1,33 +0,0 @@
.ReactModalPortal > div {
opacity: 0;
}
.ReactModalPortal .ReactModal__Overlay {
align-items: center;
display: flex;
justify-content: center;
transition: opacity 200ms ease-in-out;
}
.ReactModalPortal .ReactModal__Overlay--after-open {
opacity: 1;
}
.ReactModalPortal .ReactModal__Overlay--before-close {
opacity: 0;
}
.modal {
color: white;
max-width: 30rem;
outline: none;
text-align: center;
}
.modal__body {
margin: 0 0 0 0;
}

View file

@ -0,0 +1,71 @@
// vim: set ts=2 sw=2 et tw=80:
import React, { Component } from "react";
import {
StyledDiv
} from "./VideocmStyle";
import { Checkbox, Embed, Button, Grid, Responsive, Segment } from "semantic-ui-react";
import { RemoteService } from "../../../remote";
import { connect } from "react-redux";
import VideocamModal from "./VideocamModal";
class Light extends Component {
constructor(props) {
super(props);
this.state = { selectedVideo: undefined};
}
openModal = () => {
this.setState((state) => {
return {selectedVideo: true}
});
};
closeModal = () => {
this.setState((state) => {
return {selectedVideo:undefined}
})
}
render() {
const normalLightView = (
<div>
<StyledDiv>
<div onClick={this.openModal}>
<video autoPlay loop muted width= "100%" height="auto">
<source src="paranormal-activity.mp4" type='video/mp4' />
</video>
</div>
</StyledDiv>
<Grid columns="equal" divide padded>
<Grid.Row textAlign="center">
<Grid.Column>
<VideocamModal
selectedVideo = {this.state.selectedVideo}
closeModal = {this.closeModal}
/>
</Grid.Column>
</ Grid.Row>
</Grid>
</div>
);
return (
<div>
{this.props.device.kind === "dimmableLight"
? console.log('err')
: normalLightView}
</div>
);
}
}
const mapStateToProps = (state, ownProps) => ({
device: state.devices[ownProps.id],
});
const LightContainer = connect(mapStateToProps, RemoteService)(Light);
export default LightContainer;

View file

@ -2,14 +2,14 @@ import React from 'react';
import Modal from 'react-modal';
import { Button } from "semantic-ui-react";
const customStyles = {
const ModalStyle = {
content: {
top: '35%',
left: '50%',
top: '20%',
left: '45%',
right: 'auto',
bottom: 'auto',
marginRight: '-50%',
width: '60%',
marginRight: '-40%',
width: '80%',
transform: 'translate(-40%, -10%)',
},
};
@ -20,7 +20,7 @@ const VideocamModal = (props) => (
isOpen={!!props.selectedVideo}
contentLabel="Live Cam"
onRequestClose={props.closeModal}
style={customStyles}
style={ModalStyle}
>
{props.selectedVideo &&
<video autoPlay loop muted width= "100%" height="auto">

View file

@ -1,86 +0,0 @@
// vim: set ts=2 sw=2 et tw=80:
/**
* Users can add lights in their rooms.
* Lights are devices like bulbs, LED strip lights, lamps.
* Lights may support an intensity level (from 0% to 100%).
* Lights have an internal state that can be changed and it must
* be shown accordingly in the SmartHut views (house view and room views).
*/
import React, { Component } from "react";
import {
StyledDiv,hAbRNe
} from "./VideocmStyle";
import { Checkbox, Embed } from "semantic-ui-react";
import { RemoteService } from "../../../remote";
import { connect } from "react-redux";
class Light extends Component {
constructor(props) {
super(props);
this.state = { intensity: this.props.device.intensity, timeout: null };
this.iconOn = "/img/lightOn.svg";
this.iconOff = "/img/lightOff.svg";
}
get turnedOn() {
return this.props.device.on;
}
onClickDevice = () => {
const on = !this.turnedOn;
this.props
.saveDevice({ ...this.props.device, on })
.catch((err) => console.error("regular light update error", err));
};
getIcon = () => {
return this.turnedOn ? this.iconOn : this.iconOff;
};
render() {
const normalLightView = (
<div>
<StyledDiv>
<div onClick={this.onClickDevice}>
<Embed
autoplay={true}
brandedUI
color='white'
hd={false} id='D0WnZyxp_Wo'
placeholder='/images/image-16by9.png'
source='youtube'
style={{ width: "200rem", height: "0.5rem" }}
centered
/>
</div>
</StyledDiv>
<Checkbox toggle
padding = '0.5rem'
margin-left = '5rem'
/>
</div>
);
return (
<div>
{this.props.device.kind === "dimmableLight"
? console.log('err')
: normalLightView}
</div>
);
}
}
const mapStateToProps = (state, ownProps) => ({
device: state.devices[ownProps.id],
});
const LightContainer = connect(mapStateToProps, RemoteService)(Light);
export default LightContainer;

View file

@ -1,89 +0,0 @@
// vim: set ts=2 sw=2 et tw=80:
/**
* Users can add lights in their rooms.
* Lights are devices like bulbs, LED strip lights, lamps.
* Lights may support an intensity level (from 0% to 100%).
* Lights have an internal state that can be changed and it must
* be shown accordingly in the SmartHut views (house view and room views).
*/
import React, { Component } from "react";
import {
StyledDiv,hAbRNe
} from "./VideocmStyle";
import Modal from "react-modal";
import { Checkbox, Embed } from "semantic-ui-react";
import { RemoteService } from "../../../remote";
import { connect } from "react-redux";
class Light extends Component {
constructor(props) {
super(props);
this.state = { intensity: this.props.device.intensity, timeout: null };
this.iconOn = "/img/lightOn.svg";
this.iconOff = "/img/lightOff.svg";
}
get turnedOn() {
return this.props.device.on;
}
onClickDevice = () => {
const on = !this.turnedOn;
this.props
.saveDevice({ ...this.props.device, on })
.catch((err) => console.error("regular light update error", err));
};
getIcon = () => {
return this.turnedOn ? this.iconOn : this.iconOff;
};
render() {
const normalLightView = (
<div>
<Modal
isOpen={true}
contentLable = "Selected Video"
>
<StyledDiv>
<div onClick={this.onClickDevice}>
<Embed
autoplay={true}
brandedUI
color='white'
hd={false}
id='D0WnZyxp_Wo'
placeholder='/images/image-16by9.png'
source='youtube'
style={{ width: "200rem", height: "0.5rem" }}
centered
/>
</div>
</StyledDiv>
</Modal>
</div>
);
return (
<div>
{this.props.device.kind === "dimmableLight"
? console.log('err')
: normalLightView}
</div>
);
}
}
const mapStateToProps = (state, ownProps) => ({
device: state.devices[ownProps.id],
});
const LightContainer = connect(mapStateToProps, RemoteService)(Light);
export default LightContainer;

View file

@ -112,6 +112,7 @@ export const StyledDiv = styled.div`
}
`;
export const ButtonDimmerContainer = styled.div`
background-color: white;
padding: 3rem;