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>
|
||||||
);
|
);
|
||||||
|
@ -7,21 +7,23 @@ import './css/TrafficInfo.css';
|
|||||||
class TrafficList extends Component {
|
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 => {
|
||||||
|
entries.push(
|
||||||
|
<TrafficEntry key={i++} departure={departure} />
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
this.props.departures.forEach(departure => {
|
// Add separator between every element
|
||||||
entries.push(
|
const intersperse = (arr, sep) => arr.reduce((a,v)=>[...a,v,sep],[]).slice(0,-1);
|
||||||
<TrafficEntry key={i++} departure={departure} />
|
entries = intersperse(entries, (<hr key={i++} />));
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add separator between every element
|
// Add separator after the last element
|
||||||
const intersperse = (arr, sep) => arr.reduce((a,v)=>[...a,v,sep],[]).slice(0,-1);
|
entries.push(<hr key={i++} />);
|
||||||
entries = intersperse(entries, (<hr key={i++} />));
|
}
|
||||||
|
|
||||||
// Add separator after the last element
|
|
||||||
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