Fix traffic info crash
This commit is contained in:
parent
3b6aed2e41
commit
211257ac67
@ -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 ?
|
||||||
<button>Byt Läge</button>
|
<>
|
||||||
|
<h3>
|
||||||
|
<span>{this.props.stop.locations[0]}</span>
|
||||||
|
</h3>
|
||||||
|
<button>Byt Läge</button>
|
||||||
|
</>
|
||||||
|
:
|
||||||
|
<h3>Vänligen aktivera platsåtkomst</h3>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -8,20 +8,22 @@ class TrafficList extends Component {
|
|||||||
render() {
|
render() {
|
||||||
let entries = [];
|
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 => {
|
this.props.departures.forEach(departure => {
|
||||||
entries.push(
|
entries.push(
|
||||||
<TrafficEntry key={i++} departure={departure} />
|
<TrafficEntry key={i++} departure={departure} />
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add separator between every element
|
// Add separator between every element
|
||||||
const intersperse = (arr, sep) => arr.reduce((a,v)=>[...a,v,sep],[]).slice(0,-1);
|
const intersperse = (arr, sep) => arr.reduce((a,v)=>[...a,v,sep],[]).slice(0,-1);
|
||||||
entries = intersperse(entries, (<hr key={i++} />));
|
entries = intersperse(entries, (<hr key={i++} />));
|
||||||
|
|
||||||
// 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">
|
||||||
|
@ -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>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user