fix-navbar

This commit is contained in:
britea 2020-03-26 00:15:02 +01:00
parent ecbe64d21e
commit e5b5a2f903
18 changed files with 188 additions and 119 deletions

View file

@ -45,6 +45,7 @@ class App extends Component {
this.state = { this.state = {
loggedIn: loggedIn, loggedIn: loggedIn,
token: token, token: token,
info: "",
}; };
this.auth = this.auth.bind(this); this.auth = this.auth.bind(this);
@ -78,6 +79,7 @@ class App extends Component {
token: res.data.jwttoken, token: res.data.jwttoken,
loggedIn: true, loggedIn: true,
}); });
this.getInfo();
return res; return res;
//this.props.history.push("/dashboard"); //this.props.history.push("/dashboard");
} else { } else {

View file

@ -160,6 +160,14 @@ export var call = {
register: function (data, headers) { register: function (data, headers) {
return axios.post(config + "register", data); return axios.post(config + "register", data);
}, },
getUserInfo: function (token) {
if (!token) {
token = tkn;
}
return axios.get(config + "auth/profile", {
headers: { Authorization: "Bearer " + token },
});
},
initResetPassword: function (data, headers) { initResetPassword: function (data, headers) {
return axios.post(config + "register/init-reset-password", data); return axios.post(config + "register/init-reset-password", data);
}, },

View file

@ -1,7 +1,16 @@
import React from "react"; import React from "react";
import { Dropdown, Icon, Grid, Divider } from "semantic-ui-react"; import {
Dropdown,
Icon,
Grid,
Divider,
Button,
Label,
Responsive,
} from "semantic-ui-react";
import { Segment, Image } from "semantic-ui-react"; import { Segment, Image } from "semantic-ui-react";
import { BrowserView, MobileView } from "react-device-detect"; import { BrowserView, MobileView } from "react-device-detect";
import { call } from "../client_server";
const AvatarImage = () => ( const AvatarImage = () => (
<Image src="avatar3.png" style={{ width: "25px", height: "auto" }} centered /> <Image src="avatar3.png" style={{ width: "25px", height: "auto" }} centered />
@ -19,7 +28,28 @@ const IconHomeImage = () => (
const TitleImage = () => <Image src="sm_logo.png" size="medium" centered />; const TitleImage = () => <Image src="sm_logo.png" size="medium" centered />;
const BrowserStructure = (props) => ( export default class MyHeader extends React.Component {
constructor(props) {
super(props);
this.state = {
username: "",
};
this.getInfo();
}
getInfo() {
call.getUserInfo(this.state.token).then((res) => {
if (res.status === 200) {
this.setState({
username: res.data.username,
});
}
});
}
render() {
return (
<div>
<Responsive minWidth={768}>
<Grid columns="equal" divided inverted padded> <Grid columns="equal" divided inverted padded>
<Grid.Row color="black" textAlign="center"> <Grid.Row color="black" textAlign="center">
<Grid.Column width={3} height={0.5}> <Grid.Column width={3} height={0.5}>
@ -33,29 +63,17 @@ const BrowserStructure = (props) => (
</Segment> </Segment>
</Grid.Column> </Grid.Column>
<Grid.Column width={2} heigth={1}> <Grid.Column width={2} heigth={1}>
<AvatarImage /> <Label as="a" image color="black">
<img alt="SmartHut logo" src="smart-home.png" />
{this.state.username}
</Label>
<Divider /> <Divider />
<Dropdown item icon="setting" size="huge"> <Button onClick={this.props.logout}>Logout</Button>
<Dropdown.Menu>
<Dropdown.Item>
<Icon name="dropdown" />
<span className="text">Settings</span>
<Dropdown.Menu>
<Dropdown.Item>Document</Dropdown.Item>
<Dropdown.Item>Image</Dropdown.Item>
</Dropdown.Menu>
</Dropdown.Item>
<Dropdown.Item>See profile...</Dropdown.Item>
<Dropdown.Divider />
<Dropdown.Item onClick={props.logout}>Logout</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
</Grid.Column> </Grid.Column>
</Grid.Row> </Grid.Row>
</Grid> </Grid>
); </Responsive>
<Responsive maxWidth={768}>
const MobileStructure = (props) => (
<Grid columns="equal" divided inverted padded> <Grid columns="equal" divided inverted padded>
<Grid.Row color="black" textAlign="center"> <Grid.Row color="black" textAlign="center">
<Segment color="black" inverted> <Segment color="black" inverted>
@ -67,38 +85,16 @@ const MobileStructure = (props) => (
<IconHomeImage /> <IconHomeImage />
</Grid.Column> </Grid.Column>
<Grid.Column> <Grid.Column>
<AvatarImage /> <Label as="a" image color="black">
<img alt="SmartHut logo" src="smart-home.png" />
{this.state.username}
</Label>
<Divider /> <Divider />
<Dropdown item icon="setting" size="huge"> <Button onClick={this.props.logout}>Logout</Button>
<Dropdown.Menu>
<Dropdown.Item>
<Icon name="dropdown" />
<span className="text">Settings</span>
<Dropdown.Menu>
<Dropdown.Item>Document</Dropdown.Item>
<Dropdown.Item>Image</Dropdown.Item>
</Dropdown.Menu>
</Dropdown.Item>
<Dropdown.Item>See profile...</Dropdown.Item>
<Dropdown.Divider />
<Dropdown.Item onClick={props.logout}>Logout</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
</Grid.Column> </Grid.Column>
</Grid.Row> </Grid.Row>
</Grid> </Grid>
); </Responsive>
export default class MyHeader extends React.Component {
render() {
return (
<div>
<BrowserView>
<BrowserStructure logout={this.props.logout} />
</BrowserView>
<MobileView>
<MobileStructure />
</MobileView>
</div> </div>
); );
} }

View file

@ -71,7 +71,9 @@ export class ButtonDimmer extends Component {
} }
/> />
<img alt="icon" src="/img/buttonDimmer.svg" /> <img alt="icon" src="/img/buttonDimmer.svg" />
<span className="knob">{this.props.device.name}</span> <span className="knob">
{this.props.device.name} ({this.props.device.id})
</span>
<PlusPanel name="UP" onClick={this.increaseIntensity}> <PlusPanel name="UP" onClick={this.increaseIntensity}>
<span>&#43;</span> <span>&#43;</span>
</PlusPanel> </PlusPanel>
@ -136,7 +138,7 @@ export class KnobDimmer extends Component {
dy="0.3em" dy="0.3em"
fontWeight="bold" fontWeight="bold"
> >
{this.props.device.name} {this.props.device.name} ({this.props.device.id})
</text> </text>
<CircularProgress <CircularProgress
style={{ ...KnobProgress, opacity: this.state.value + 0.1 }} style={{ ...KnobProgress, opacity: this.state.value + 0.1 }}

View file

@ -49,6 +49,9 @@ export const textStyle = {
fill: "#1a2849", fill: "#1a2849",
fontSize: "1.5rem", fontSize: "1.5rem",
fontFamily: "Lato", fontFamily: "Lato",
overflow: "hidden",
whiteSpace: "nowrap",
textOverflow: "ellipsis",
}; };
export const knobIcon = { export const knobIcon = {

View file

@ -84,6 +84,10 @@ export default class Light extends Component {
}); });
}; };
get intensity() {
return isNaN(this.state.intensity) ? 0 : this.state.intensity;
}
render() { render() {
const intensityLightView = ( const intensityLightView = (
<div style={LightDimmerContainer}> <div style={LightDimmerContainer}>
@ -96,7 +100,7 @@ export default class Light extends Component {
/> />
<CircularInput <CircularInput
style={LightDimmerStyle} style={LightDimmerStyle}
value={+(Math.round(this.state.intensity / 100 + "e+2") + "e-2")} value={+(Math.round(this.intensity / 100 + "e+2") + "e-2")}
onChange={this.setIntensity} onChange={this.setIntensity}
> >
<text <text
@ -107,12 +111,12 @@ export default class Light extends Component {
dy="0.3em" dy="0.3em"
fontWeight="bold" fontWeight="bold"
> >
{this.props.device.name} {this.props.device.name} <br /> ({this.props.device.id})
</text> </text>
<CircularProgress <CircularProgress
style={{ style={{
...KnobProgress, ...KnobProgress,
opacity: this.state.intensity / 100 + 0.3, opacity: this.intensity / 100 + 0.3,
}} }}
/> />
<CircularThumb style={CircularThumbStyle} /> <CircularThumb style={CircularThumbStyle} />
@ -134,7 +138,9 @@ export default class Light extends Component {
<div onClick={this.props.edit.mode ? () => {} : this.onClickDevice}> <div onClick={this.props.edit.mode ? () => {} : this.onClickDevice}>
<Image src={this.getIcon()} style={iconStyle} /> <Image src={this.getIcon()} style={iconStyle} />
<BottomPanel style={{ backgroundColor: "#ffa41b" }}> <BottomPanel style={{ backgroundColor: "#ffa41b" }}>
<h5 style={nameStyle}>{this.props.device.name}</h5> <h5 style={nameStyle}>
{this.props.device.name} ({this.props.device.id})
</h5>
</BottomPanel> </BottomPanel>
</div> </div>
</StyledDiv> </StyledDiv>

View file

@ -17,6 +17,9 @@ export const textStyle = {
fill: "#ffd31d", fill: "#ffd31d",
fontSize: "1.5rem", fontSize: "1.5rem",
fontFamily: "Lato", fontFamily: "Lato",
overflow: "hidden",
whiteSpace: "nowrap",
textOverflow: "ellipsis",
}; };
export const nameStyle = { export const nameStyle = {

View file

@ -110,7 +110,7 @@ export default class NewDevice extends Component {
if (this.state.name === "") { if (this.state.name === "") {
data.params["name"] = "Dimmable Light"; data.params["name"] = "Dimmable Light";
} }
data.params["intensity"] = 1; data.params["intensity"] = 0;
break; break;
case "sensor": case "sensor":
if (this.state.name === "") { if (this.state.name === "") {

View file

@ -175,7 +175,7 @@ export default class Sensor extends Component {
dy="0.4em" dy="0.4em"
fontWeight="bold" fontWeight="bold"
> >
{this.setName()} {this.setName()} ({this.props.device.id})
</text> </text>
</CircularInput> </CircularInput>
<Image style={iconSensorStyle} src={`/img/${this.icon}`} /> <Image style={iconSensorStyle} src={`/img/${this.icon}`} />

View file

@ -18,6 +18,9 @@ export const sensorText = {
fill: "#3e99ff", fill: "#3e99ff",
fontSize: "1.2rem", fontSize: "1.2rem",
fontFamily: "Lato", fontFamily: "Lato",
overflow: "hidden",
whiteSpace: "nowrap",
textOverflow: "ellipsis",
}; };
export const valueStyle = { export const valueStyle = {
@ -61,6 +64,9 @@ export const nameMotionStyle = {
left: "50%", left: "50%",
transform: "translateX(-50%)", transform: "translateX(-50%)",
fontSize: "1.2rem", fontSize: "1.2rem",
overflow: "hidden",
whiteSpace: "nowrap",
textOverflow: "ellipsis",
}; };
export const motionSensorIcon = { export const motionSensorIcon = {

View file

@ -75,7 +75,9 @@ export default class SmartPlug extends Component {
} }
/> />
<Image src={this.getIcon()} style={imageStyle} /> <Image src={this.getIcon()} style={imageStyle} />
<span style={nameStyle}>{this.props.device.name}</span> <span style={nameStyle}>
{this.props.device.name} ({this.props.device.id})
</span>
<BottomPanel <BottomPanel
style={ style={

View file

@ -32,4 +32,7 @@ export const nameStyle = {
top: "30%", top: "30%",
left: "50%", left: "50%",
transform: "translateX(-50%)", transform: "translateX(-50%)",
overflow: "hidden",
whiteSpace: "nowrap",
textOverflow: "ellipsis",
}; };

View file

@ -67,7 +67,9 @@ export default class Switch extends Component {
/> />
<Image src={this.getIcon()} style={imageStyle} /> <Image src={this.getIcon()} style={imageStyle} />
<span style={nameStyle}>{this.props.device.name}</span> <span style={nameStyle}>
{this.props.device.name} ({this.props.device.id})
</span>
<BottomPanel <BottomPanel
style={ style={

View file

@ -13,6 +13,9 @@ export const nameStyle = {
top: "30%", top: "30%",
left: "50%", left: "50%",
transform: "translateX(-50%)", transform: "translateX(-50%)",
overflow: "hidden",
whiteSpace: "nowrap",
textOverflow: "ellipsis",
}; };
export const turnedOnStyle = { export const turnedOnStyle = {

View file

@ -17,13 +17,17 @@ export default class ModalWindow extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
console.table(this.props); if (typeof this.props.idRoom === "function") {
this.idRoom = this.props.idRoom();
} else {
this.idRoom = this.props.idRoom;
}
this.state = { this.state = {
id: "", id: "",
selectedIcon: "", selectedIcon: "",
name: this.props.type === "new" ? "Device" : this.props.idRoom.name, name: this.props.type === "new" ? "New Room" : this.idRoom.name,
img: this.props.type === "new" ? null : this.props.idRoom.image, img: this.props.type === "new" ? null : this.idRoom.image,
openModal: false, openModal: false,
}; };
@ -50,9 +54,9 @@ export default class ModalWindow extends Component {
let data = { let data = {
icon: icon:
this.state.selectedIcon === "" this.state.selectedIcon === ""
? this.props.idRoom.icon ? this.idRoom.icon
: this.state.selectedIcon, : this.state.selectedIcon,
name: this.state.name === "" ? this.props.idRoom.name : this.state.name, name: this.state.name === "" ? this.idRoom.name : this.state.name,
image: this.state.img, image: this.state.img,
}; };
this.props.updateRoom(data); this.props.updateRoom(data);
@ -98,7 +102,7 @@ export default class ModalWindow extends Component {
padding: "10px 10px", padding: "10px 10px",
margin: "10px 0px", margin: "10px 0px",
}; };
console.log(this.state, this.idRoom);
return ( return (
<div> <div>
<Responsive minWidth={768}> <Responsive minWidth={768}>
@ -167,7 +171,7 @@ export default class ModalWindow extends Component {
<SelectIcons <SelectIcons
updateIcon={this.updateIcon} updateIcon={this.updateIcon}
currentIcon={ currentIcon={
this.props.type === "new" ? "home" : this.props.idRoom.icon this.props.type === "new" ? "home" : this.idRoom.icon
} }
/> />
</div> </div>

View file

@ -168,10 +168,7 @@ export default class Dashboard extends Component {
call call
.devicePost(data, this.props.tkn) .devicePost(data, this.props.tkn)
.then((res) => { .then((res) => {
this.setState((state) => ({ this.getDevices();
devices: state.devices.concat([res.data]),
}));
return this.state.devices;
}) })
.catch((err) => {}); .catch((err) => {});
} }

View file

@ -207,11 +207,6 @@ const Home = () => (
<Image bordered rounded size="large" src="/img/banner.jpg" /> <Image bordered rounded size="large" src="/img/banner.jpg" />
</Grid.Column> </Grid.Column>
</Grid.Row> </Grid.Row>
<Grid.Row>
<Grid.Column textAlign="center">
<Button size="huge">Check It Out</Button>
</Grid.Column>
</Grid.Row>
</Grid> </Grid>
</Segment> </Segment>
@ -226,9 +221,6 @@ const Home = () => (
the set the illumination of your entire place. Follow the intelligent the set the illumination of your entire place. Follow the intelligent
light, follow SmartHut. light, follow SmartHut.
</p> </p>
<Button as="a" size="large">
Read More
</Button>
</Container> </Container>
</Segment> </Segment>
@ -239,19 +231,57 @@ const Home = () => (
<Grid.Column width={3}> <Grid.Column width={3}>
<Header inverted as="h4" content="About" /> <Header inverted as="h4" content="About" />
<List link inverted> <List link inverted>
<List.Item as="a">Sitemap</List.Item> <List.Item>
<List.Item as="a">Contact Us</List.Item> <a href="https://usi.ch" target="blank">
<List.Item as="a">Religious Ceremonies</List.Item> Usi
<List.Item as="a">Gazebo Plans</List.Item> </a>
</List.Item>
<List.Item>
<a href="https://vimtok.com" target="blank">
VimTok
</a>
</List.Item>
<List.Item>
<a href="https://legendofajax.fun" target="blank">
Legend of Ajax
</a>
</List.Item>
<List.Item>
<a href="https://theshell.ch" target="blank">
The Shell
</a>
</List.Item>
</List> </List>
</Grid.Column> </Grid.Column>
<Grid.Column width={3}> <Grid.Column width={3}>
<Header inverted as="h4" content="Services" /> <Header inverted as="h4" content="Services" />
<List link inverted> <List link inverted>
<List.Item as="a">Banana Pre-Order</List.Item> <List.Item>
<List.Item as="a">DNA FAQ</List.Item> <a href="https://semantic-ui.com/" target="blank">
<List.Item as="a">How To Access</List.Item> Semantic UI
<List.Item as="a">Favorite X-Men</List.Item> </a>
</List.Item>
<List.Item>
<a
href="https://worldmeters.info/coronavirus/"
target="blank"
>
Stay Safe
</a>
</List.Item>
<List.Item>
<a
href="http://hasthelargehadroncolliderdestroyedtheworldyet.com/"
target="blank"
>
Stay Home
</a>
</List.Item>
<List.Item>
<a href="http://Howmuchtoiletpaper.com/" target="blank">
Can you Survive?
</a>
</List.Item>
</List> </List>
</Grid.Column> </Grid.Column>
<Grid.Column width={7}> <Grid.Column width={7}>

View file

@ -26,19 +26,18 @@ class Navbar extends Component {
handleClick = (e, { id, name }) => { handleClick = (e, { id, name }) => {
const room = this.props.rooms.filter((d) => d.id === id)[0]; const room = this.props.rooms.filter((d) => d.id === id)[0];
console.log(room);
this.setState({ this.setState({
activeItem: id, activeItem: id,
activeRoom: room,
activeItemName: name, activeItemName: name,
}); });
this.activeRoom = room;
console.log(this.activeRoom);
this.forceUpdate(); this.forceUpdate();
console.log(this.state.activeRoom);
this.props.handleItemClick(id); this.props.handleItemClick(id);
}; };
render() { render() {
const { activeRoom } = this.state;
console.log("DIO", activeRoom);
return ( return (
<div style={{ background: "#1b1c1d!important", padding: "0 20px" }}> <div style={{ background: "#1b1c1d!important", padding: "0 20px" }}>
<Responsive minWidth={768}> <Responsive minWidth={768}>
@ -170,7 +169,10 @@ class Navbar extends Component {
<Grid.Column width={8}> <Grid.Column width={8}>
<ModalWindow <ModalWindow
type="modify" type="modify"
idRoom={activeRoom} idRoom={() => {
console.log("MALUSA", this.activeRoom);
return this.activeRoom;
}}
updateRoom={this.props.updateRoom} updateRoom={this.props.updateRoom}
deleteRoom={this.props.deleteRoom} deleteRoom={this.props.deleteRoom}
/> />