hallbarUtvecklingVT7/src/components/DisruptionButton.js
2020-12-10 11:47:46 +01:00

66 lines
1.7 KiB
JavaScript

import addNotification from "react-push-notification";
import globData from '../GlobalData.js';
import ex1 from '../APIexamples/disruption1.json'
import ex2 from '../APIexamples/disruption2.json'
import Button from './Button.js';
import disruptIcon from '../img/flash.svg';
import globalData from '../GlobalData.js'
class DisruptionButton extends Button {
state = {
jsonLocation: this.props.path,
disruption: ""
}
updatePage = () => {
globalData.currentPage.forceUpdate();
}
genDisrupt = () => {
this.state.disruption = undefined
if(this.state.jsonLocation === "ex1"){
for (let stopPoint of ex1.affectedStopPoints) {
if(stopPoint.gid === globData.user.stoppointgid){
this.state.disruption = ex1;
globData.stop.departures[0].newTime = ex1.time;
globData.stop.departures[0].trafficInfo = ex1.title;
}
}
} else if (this.state.jsonLocation === "ex2"){
for (let stopPoint of ex2.affectedStopPoints) {
if(stopPoint.gid === globData.user.stoppointgid){
this.state.disruption = ex2;
globData.stop.departures[0].newTime = ex2.time;
globData.stop.departures[0].trafficInfo = ex2.title;
}
}
}
globData.disruption = this.state.disruption
addNotification({
title: "Warning",
subtitle: "This is a subtitle",
message: "This is a very long message",
theme: "blue",
native: true, // when using native, your OS will handle theming.
});
}
render() {
return (
<Button onClick={this.props.onClick.concat([this.genDisrupt,this.updatePage])} className="disruptBtn">
<img src={disruptIcon} alt="" />
<span>Generera Störning</span>
</Button>
);
}
}
export default DisruptionButton;