Add: Select user buttons

This commit is contained in:
williameriksson126 2020-12-08 11:54:34 +01:00
parent c7517f185c
commit 3c0fc6fe1f
7 changed files with 49 additions and 10 deletions

View File

@ -1,5 +1,5 @@
{ {
"name":"1", "name":"1",
"deviceId":"1", "deviceId":"1",
"location":"9022014014754001" "stoppointgid":"9022014014754001"
} }

View File

@ -1,5 +1,5 @@
{ {
"name":"2", "name":"2",
"deviceId":"2", "deviceId":"2",
"location":"9022014014020001" "stoppointgid":"9022014014020001"
} }

View File

@ -1,5 +1,5 @@
{ {
"name":"3", "name":"3",
"deviceId":"3", "deviceId":"3",
"location":"9022014014751001" "stoppointgid":"9022014014751001"
} }

View File

@ -1,5 +1,5 @@
{ {
"name":"4", "name":"4",
"deviceId":"4", "deviceId":"4",
"location":"9021014014225000" "stoppointgid":"9021014014225000"
} }

View File

@ -11,23 +11,21 @@ import disruptIcon from '../img/flash.svg';
class DisruptionButton extends Button { class DisruptionButton extends Button {
state = { state = {
jsonLocation: this.props.path, jsonLocation: this.props.path,
user: globData.user,
disruption: "" disruption: ""
} }
genDisrupt = () => { genDisrupt = () => {
console.log(globData.disruption) this.state.disruption = ""
for (let stopPoint of ex1.affectedStopPoints) { for (let stopPoint of ex1.affectedStopPoints) {
if(stopPoint.gid === this.state.user.stoppointgid){ if(stopPoint.gid === globData.user.stoppointgid){
this.state.disruption = ex1 this.state.disruption = ex1
} }
} }
console.log(this.state.disruption)
globData.disruption = this.state.disruption globData.disruption = this.state.disruption
console.log(globData.disruption)
addNotification({ addNotification({
title: "Warning", title: "Warning",
subtitle: "This is a subtitle", subtitle: "This is a subtitle",

View File

@ -2,6 +2,7 @@ import React, { Component } from 'react';
import globalData from '../GlobalData.js'; import globalData from '../GlobalData.js';
import DisruptionButton from "./DisruptionButton.js"; import DisruptionButton from "./DisruptionButton.js";
import SelectUserButton from "./SelectUserButton.js"
import Popup from './Popup.js'; import Popup from './Popup.js';
import Button from './Button.js'; import Button from './Button.js';
@ -63,6 +64,10 @@ class NavigationDrawer extends Component {
<span>example@gmail.com</span> <span>example@gmail.com</span>
</header> </header>
<div id="navList"> <div id="navList">
<SelectUserButton path={"user1"} username="user1"/>
<SelectUserButton path={"user2"} username="user2"/>
<SelectUserButton path={"user3"} username="user3"/>
<SelectUserButton path={"user4"} username="user4"/>
<DisruptionButton path={"ex1"} onClick={[this.showPopup, this.close]} /> <DisruptionButton path={"ex1"} onClick={[this.showPopup, this.close]} />
</div> </div>
<hr /> <hr />

View File

@ -0,0 +1,36 @@
import globData from '../GlobalData.js';
import user1 from '../APIexamples/user1.json'
import user2 from '../APIexamples/user2.json'
import user3 from '../APIexamples/user3.json'
import user4 from '../APIexamples/user4.json'
import Button from './Button.js';
import disruptIcon from '../img/flash.svg';
class SelectUserButton extends Button {
selectUser = () => {
if(this.props.path === "user1"){
globData.user = user1
}else if (this.props.path === "user2"){
globData.user = user2
}else if (this.props.path === "user3"){
globData.user = user3
}else if (this.props.path === "user4"){
globData.user = user4
}
}
render() {
return (
<Button onClick={[this.selectUser]} className="disruptBtn">
<img src={disruptIcon} alt="" />
<span>{this.props.username}</span>
</Button>
);
}
}
export default SelectUserButton;