Fix traffic info crash
This commit is contained in:
parent
3b6aed2e41
commit
211257ac67
@ -6,10 +6,21 @@ class StopTitle extends Component {
|
||||
render() {
|
||||
return (
|
||||
<div id="stopTitle">
|
||||
<h1>{this.props.stop.name}</h1>
|
||||
<h1>{this.props.stop.name !== undefined ?
|
||||
this.props.stop.name
|
||||
: "Hållplats saknas"
|
||||
}</h1>
|
||||
<div>
|
||||
<h3>{this.props.stop.locations[0]}</h3>
|
||||
<button>Byt Läge</button>
|
||||
{this.props.stop.locations !== undefined ?
|
||||
<>
|
||||
<h3>
|
||||
<span>{this.props.stop.locations[0]}</span>
|
||||
</h3>
|
||||
<button>Byt Läge</button>
|
||||
</>
|
||||
:
|
||||
<h3>Vänligen aktivera platsåtkomst</h3>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
@ -8,20 +8,22 @@ class TrafficList extends Component {
|
||||
render() {
|
||||
let entries = [];
|
||||
|
||||
let i = 0; // React requires elems in array to have associated unique key
|
||||
if (this.props.departures) {
|
||||
let i = 0; // React requires elems in array to have associated unique key
|
||||
|
||||
this.props.departures.forEach(departure => {
|
||||
entries.push(
|
||||
<TrafficEntry key={i++} departure={departure} />
|
||||
);
|
||||
});
|
||||
this.props.departures.forEach(departure => {
|
||||
entries.push(
|
||||
<TrafficEntry key={i++} departure={departure} />
|
||||
);
|
||||
});
|
||||
|
||||
// Add separator between every element
|
||||
const intersperse = (arr, sep) => arr.reduce((a,v)=>[...a,v,sep],[]).slice(0,-1);
|
||||
entries = intersperse(entries, (<hr key={i++} />));
|
||||
// Add separator between every element
|
||||
const intersperse = (arr, sep) => arr.reduce((a,v)=>[...a,v,sep],[]).slice(0,-1);
|
||||
entries = intersperse(entries, (<hr key={i++} />));
|
||||
|
||||
// Add separator after the last element
|
||||
entries.push(<hr key={i++} />);
|
||||
// Add separator after the last element
|
||||
entries.push(<hr key={i++} />);
|
||||
}
|
||||
|
||||
return (
|
||||
<div id="trafficList">
|
||||
|
@ -6,38 +6,19 @@ import MainArea from "../MainArea.js";
|
||||
import StopTitle from "../StopTitle.js";
|
||||
import TrafficList from "../TrafficList.js";
|
||||
|
||||
import Stop from "../../classes/Stop.js";
|
||||
import Departure from "../../classes/Departure.js";
|
||||
import globalData from '../../GlobalData.js';
|
||||
|
||||
|
||||
class TrafficInfo extends Component {
|
||||
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 (
|
||||
<>
|
||||
<Header title="Trafikinfo" />
|
||||
<TopMenu>
|
||||
<StopTitle stop={testStop} />
|
||||
<StopTitle stop={globalData.stop} />
|
||||
</TopMenu>
|
||||
<MainArea>
|
||||
<TrafficList departures={testStop.departures} />
|
||||
<TrafficList departures={globalData.stop.departures} />
|
||||
</MainArea>
|
||||
</>
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user