From 211257ac67725f82febd447231df3277129db42e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wahlberg?= Date: Thu, 10 Dec 2020 10:23:52 +0100 Subject: [PATCH] Fix traffic info crash --- src/components/StopTitle.js | 17 ++++++++++++++--- src/components/TrafficList.js | 26 ++++++++++++++------------ src/components/pages/TrafficInfo.js | 25 +++---------------------- 3 files changed, 31 insertions(+), 37 deletions(-) diff --git a/src/components/StopTitle.js b/src/components/StopTitle.js index d2bf05c..bd92f33 100644 --- a/src/components/StopTitle.js +++ b/src/components/StopTitle.js @@ -6,10 +6,21 @@ class StopTitle extends Component { render() { return (
-

{this.props.stop.name}

+

{this.props.stop.name !== undefined ? + this.props.stop.name + : "Hållplats saknas" + }

-

{this.props.stop.locations[0]}

- + {this.props.stop.locations !== undefined ? + <> +

+ {this.props.stop.locations[0]} +

+ + + : +

Vänligen aktivera platsåtkomst

+ }
); diff --git a/src/components/TrafficList.js b/src/components/TrafficList.js index c91101c..9dd9d52 100644 --- a/src/components/TrafficList.js +++ b/src/components/TrafficList.js @@ -7,21 +7,23 @@ import './css/TrafficInfo.css'; class TrafficList extends Component { render() { 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( + + ); + }); - this.props.departures.forEach(departure => { - entries.push( - - ); - }); + // Add separator between every element + const intersperse = (arr, sep) => arr.reduce((a,v)=>[...a,v,sep],[]).slice(0,-1); + entries = intersperse(entries, (
)); - // Add separator between every element - const intersperse = (arr, sep) => arr.reduce((a,v)=>[...a,v,sep],[]).slice(0,-1); - entries = intersperse(entries, (
)); - - // Add separator after the last element - entries.push(
); + // Add separator after the last element + entries.push(
); + } return (
diff --git a/src/components/pages/TrafficInfo.js b/src/components/pages/TrafficInfo.js index 265b2bf..1ef2b96 100644 --- a/src/components/pages/TrafficInfo.js +++ b/src/components/pages/TrafficInfo.js @@ -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 ( <>
- + - + );