Fix traffic info crash

This commit is contained in:
André Wahlberg 2020-12-10 10:23:52 +01:00
parent 3b6aed2e41
commit 211257ac67
3 changed files with 31 additions and 37 deletions

View File

@ -6,10 +6,21 @@ class StopTitle extends Component {
render() { render() {
return ( return (
<div id="stopTitle"> <div id="stopTitle">
<h1>{this.props.stop.name}</h1> <h1>{this.props.stop.name !== undefined ?
this.props.stop.name
: "Hållplats saknas"
}</h1>
<div> <div>
<h3>{this.props.stop.locations[0]}</h3> {this.props.stop.locations !== undefined ?
<>
<h3>
<span>{this.props.stop.locations[0]}</span>
</h3>
<button>Byt Läge</button> <button>Byt Läge</button>
</>
:
<h3>Vänligen aktivera platsåtkomst</h3>
}
</div> </div>
</div> </div>
); );

View File

@ -8,6 +8,7 @@ class TrafficList extends Component {
render() { render() {
let entries = []; let entries = [];
if (this.props.departures) {
let i = 0; // React requires elems in array to have associated unique key let i = 0; // React requires elems in array to have associated unique key
this.props.departures.forEach(departure => { this.props.departures.forEach(departure => {
@ -22,6 +23,7 @@ class TrafficList extends Component {
// Add separator after the last element // Add separator after the last element
entries.push(<hr key={i++} />); entries.push(<hr key={i++} />);
}
return ( return (
<div id="trafficList"> <div id="trafficList">

View File

@ -6,38 +6,19 @@ import MainArea from "../MainArea.js";
import StopTitle from "../StopTitle.js"; import StopTitle from "../StopTitle.js";
import TrafficList from "../TrafficList.js"; import TrafficList from "../TrafficList.js";
import Stop from "../../classes/Stop.js"; import globalData from '../../GlobalData.js';
import Departure from "../../classes/Departure.js";
class TrafficInfo extends Component { class TrafficInfo extends Component {
render() { render() {
/* TEST DATA - TO BE REPLACED */
let testStop = new Stop(
"Lemmingsgatan",
["Läge A", "Läge B", "Läge C"],
[
new Departure(
"519",
"Heden",
"11:59",
"Trafikolycka vid Partille Centrum. Olyckan ska ha inträffat i höjd med brandstationen och det är oklart om någon är skadad. Polis på väg. Två av bilarna behöver bärgas från platsen. Inga uppgifter om personskador."
),
new Departure("58", "Västra Eriksberg", "12:07"),
]
);
testStop.departures[0].timeUpdate("16:50");
/* TEST DATA - TO BE REPLACED */
return ( return (
<> <>
<Header title="Trafikinfo" /> <Header title="Trafikinfo" />
<TopMenu> <TopMenu>
<StopTitle stop={testStop} /> <StopTitle stop={globalData.stop} />
</TopMenu> </TopMenu>
<MainArea> <MainArea>
<TrafficList departures={testStop.departures} /> <TrafficList departures={globalData.stop.departures} />
</MainArea> </MainArea>
</> </>
); );