2020-03-19 10:52:13 +00:00
|
|
|
import React from "react";
|
2020-05-05 13:53:07 +00:00
|
|
|
import {
|
|
|
|
Grid,
|
|
|
|
Divider,
|
|
|
|
Button,
|
|
|
|
Label,
|
|
|
|
Responsive,
|
|
|
|
Checkbox,
|
|
|
|
} from "semantic-ui-react";
|
2020-03-23 20:24:17 +00:00
|
|
|
import { Segment, Image } from "semantic-ui-react";
|
2020-04-09 11:59:34 +00:00
|
|
|
import { RemoteService } from "../remote";
|
|
|
|
import { withRouter } from "react-router-dom";
|
|
|
|
import { connect } from "react-redux";
|
2020-03-13 13:43:31 +00:00
|
|
|
|
2020-03-23 20:24:17 +00:00
|
|
|
const IconHomeImage = () => (
|
|
|
|
<Image
|
|
|
|
src="smart-home.png"
|
|
|
|
style={{ width: "50px", height: "auto" }}
|
|
|
|
centered
|
|
|
|
as="a"
|
|
|
|
href="/"
|
|
|
|
/>
|
|
|
|
);
|
2020-03-13 13:43:31 +00:00
|
|
|
|
2020-03-25 14:43:03 +00:00
|
|
|
const TitleImage = () => <Image src="sm_logo.png" size="medium" centered />;
|
2020-03-24 09:10:49 +00:00
|
|
|
|
2020-04-09 11:59:34 +00:00
|
|
|
export class MyHeader extends React.Component {
|
2020-03-25 23:15:02 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.getInfo();
|
2020-04-09 12:48:24 +00:00
|
|
|
this.logout = this.logout.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
logout() {
|
|
|
|
this.props.logout().then(() => this.props.history.push("/"));
|
2020-03-25 23:15:02 +00:00
|
|
|
}
|
2020-04-09 11:59:34 +00:00
|
|
|
|
2020-03-25 23:15:02 +00:00
|
|
|
getInfo() {
|
2020-04-09 11:59:34 +00:00
|
|
|
this.props
|
|
|
|
.fetchUserInfo()
|
|
|
|
.catch((err) => console.error("MyHeader fetch user info error", err));
|
2020-03-25 23:15:02 +00:00
|
|
|
}
|
2020-04-09 11:59:34 +00:00
|
|
|
|
2020-05-05 13:53:07 +00:00
|
|
|
setCameraEnabled(val) {
|
|
|
|
let enabled = {
|
|
|
|
cameraEnabled: val,
|
|
|
|
};
|
|
|
|
this.props
|
|
|
|
.userPermissions(enabled)
|
|
|
|
.then(() => this.getInfo())
|
|
|
|
.catch((err) => console.error("Camera enabled", err));
|
|
|
|
}
|
|
|
|
|
2020-03-24 09:10:49 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
2020-03-25 23:15:02 +00:00
|
|
|
<Responsive minWidth={768}>
|
|
|
|
<Grid columns="equal" divided inverted padded>
|
|
|
|
<Grid.Row color="black" textAlign="center">
|
2020-05-06 09:13:17 +00:00
|
|
|
<Grid.Column width={4} height={0.5}>
|
2020-03-25 23:15:02 +00:00
|
|
|
<Segment color="black" inverted>
|
|
|
|
<IconHomeImage />
|
|
|
|
</Segment>
|
|
|
|
</Grid.Column>
|
|
|
|
<Grid.Column>
|
|
|
|
<Segment color="black" inverted>
|
|
|
|
<TitleImage />
|
|
|
|
</Segment>
|
|
|
|
</Grid.Column>
|
2020-05-06 09:13:17 +00:00
|
|
|
<Grid.Column width={4} heigth={1}>
|
2020-03-25 23:15:02 +00:00
|
|
|
<Label as="a" image color="black">
|
|
|
|
<img alt="SmartHut logo" src="smart-home.png" />
|
2020-04-11 16:29:32 +00:00
|
|
|
{this.props.username}
|
2020-03-25 23:15:02 +00:00
|
|
|
</Label>
|
|
|
|
<Divider />
|
2020-04-17 12:25:22 +00:00
|
|
|
<Button basic inverted onClick={this.logout}>
|
|
|
|
Logout
|
|
|
|
</Button>
|
2020-05-06 09:13:17 +00:00
|
|
|
<Segment compact style={{margin: "auto", marginTop: "1em", textAlign: "center"}}>
|
2020-05-05 13:53:07 +00:00
|
|
|
<Checkbox
|
2020-05-06 09:13:17 +00:00
|
|
|
label={<label
|
|
|
|
>Share cameras</label>}
|
2020-05-05 13:53:07 +00:00
|
|
|
checked={this.props.cameraEnabled}
|
|
|
|
toggle
|
|
|
|
onChange={(e, val) => this.setCameraEnabled(val.checked)}
|
|
|
|
/>
|
2020-05-06 09:13:17 +00:00
|
|
|
</Segment>
|
2020-03-25 23:15:02 +00:00
|
|
|
</Grid.Column>
|
|
|
|
</Grid.Row>
|
|
|
|
</Grid>
|
|
|
|
</Responsive>
|
|
|
|
<Responsive maxWidth={768}>
|
|
|
|
<Grid columns="equal" divided inverted padded>
|
|
|
|
<Grid.Row color="black" textAlign="center">
|
|
|
|
<Segment color="black" inverted>
|
|
|
|
<TitleImage />
|
|
|
|
</Segment>
|
|
|
|
</Grid.Row>
|
|
|
|
<Grid.Row color="black" textAlign="center">
|
|
|
|
<Grid.Column>
|
|
|
|
<IconHomeImage />
|
|
|
|
</Grid.Column>
|
|
|
|
<Grid.Column>
|
|
|
|
<Label as="a" image color="black">
|
|
|
|
<img alt="SmartHut logo" src="smart-home.png" />
|
2020-04-11 16:29:32 +00:00
|
|
|
{this.props.username}
|
2020-03-25 23:15:02 +00:00
|
|
|
</Label>
|
|
|
|
<Divider />
|
2020-04-11 16:29:32 +00:00
|
|
|
<Button onClick={this.logout}>Logout</Button>
|
2020-05-06 09:13:17 +00:00
|
|
|
<Segment compact style={{margin: "auto", marginTop: "1em", textAlign: "center"}}>
|
|
|
|
<Checkbox
|
|
|
|
label={<label
|
|
|
|
>Share cameras</label>}
|
|
|
|
checked={this.props.cameraEnabled}
|
|
|
|
toggle
|
|
|
|
onChange={(e, val) => this.setCameraEnabled(val.checked)}
|
|
|
|
/>
|
|
|
|
</Segment>
|
2020-03-25 23:15:02 +00:00
|
|
|
</Grid.Column>
|
|
|
|
</Grid.Row>
|
|
|
|
</Grid>
|
|
|
|
</Responsive>
|
2020-03-24 09:10:49 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-04-09 11:59:34 +00:00
|
|
|
|
|
|
|
const mapStateToProps = (state, _) => ({
|
|
|
|
username:
|
|
|
|
state.userInfo && state.userInfo.username ? state.userInfo.username : "",
|
2020-05-05 13:53:07 +00:00
|
|
|
cameraEnabled: state.userInfo ? state.userInfo.cameraEnabled : false,
|
2020-04-09 11:59:34 +00:00
|
|
|
});
|
|
|
|
const LoginContainer = connect(
|
|
|
|
mapStateToProps,
|
|
|
|
RemoteService
|
|
|
|
)(withRouter(MyHeader));
|
|
|
|
export default LoginContainer;
|