From d304b250a24768b288d38b07ce90073a36ca3f7b Mon Sep 17 00:00:00 2001 From: williameriksson126 Date: Wed, 9 Dec 2020 17:54:28 +0100 Subject: [PATCH] Add: Json files for nearby busstops and a component for accessing said json files --- src/APIexamples/locationuser1.json | 36 ++++++++++++++++++++++++++ src/APIexamples/locationuser2.json | 36 ++++++++++++++++++++++++++ src/APIexamples/locationuser3.json | 36 ++++++++++++++++++++++++++ src/APIexamples/locationuser4.json | 35 +++++++++++++++++++++++++ src/GlobalData.js | 5 +++- src/classes/Stop.js | 5 +++- src/components/FindStops.js | 41 ++++++++++++++++++++++++++++++ src/components/StopSelector.js | 0 8 files changed, 192 insertions(+), 2 deletions(-) create mode 100644 src/APIexamples/locationuser1.json create mode 100644 src/APIexamples/locationuser2.json create mode 100644 src/APIexamples/locationuser3.json create mode 100644 src/APIexamples/locationuser4.json create mode 100644 src/components/FindStops.js create mode 100644 src/components/StopSelector.js diff --git a/src/APIexamples/locationuser1.json b/src/APIexamples/locationuser1.json new file mode 100644 index 0000000..8288ff8 --- /dev/null +++ b/src/APIexamples/locationuser1.json @@ -0,0 +1,36 @@ +{ + "LocationList": { + "noNamespaceSchemaLocation": "http://api.vasttrafik.se/v1/hafasRestLocation.xsd", + "servertime": "16:48", + "serverdate": "2020-12-09", + "StopLocation": [ + { + "name": "Bollestadsvägen, Kungälv", + "id": "9022014014754001", + "lat": "57.888940", + "lon": "11.885663", + "track": "A" + }, + { + "name": "Bollestadsvägen, Kungälv", + "id": "9021014014754000", + "lat": "57.889030", + "lon": "11.885708" + }, + { + "name": "Bollestadsvägen, Kungälv", + "id": "9022014014754002", + "lat": "57.889111", + "lon": "11.885753", + "track": "B" + }, + { + "name": "Bredsten, Kungälv", + "id": "9022014014753002", + "lat": "57.886450", + "lon": "11.889529", + "track": "B" + } + ] + } + } \ No newline at end of file diff --git a/src/APIexamples/locationuser2.json b/src/APIexamples/locationuser2.json new file mode 100644 index 0000000..decace7 --- /dev/null +++ b/src/APIexamples/locationuser2.json @@ -0,0 +1,36 @@ +{ + "LocationList": { + "noNamespaceSchemaLocation": "http://api.vasttrafik.se/v1/hafasRestLocation.xsd", + "servertime": "16:47", + "serverdate": "2020-12-09", + "StopLocation": [ + { + "name": "Ekelöv västra, Kungälv", + "id": "9022014014020001", + "lat": "57.892527", + "lon": "11.865321", + "track": "A" + }, + { + "name": "Ekelöv västra, Kungälv", + "id": "9021014014020000", + "lat": "57.892608", + "lon": "11.865312" + }, + { + "name": "Ekelöv västra, Kungälv", + "id": "9022014014020002", + "lat": "57.892689", + "lon": "11.865285", + "track": "B" + }, + { + "name": "Ekelöv östra, Kungälv", + "id": "9022014014021002", + "lat": "57.892994", + "lon": "11.873923", + "track": "B" + } + ] + } + } \ No newline at end of file diff --git a/src/APIexamples/locationuser3.json b/src/APIexamples/locationuser3.json new file mode 100644 index 0000000..450cfe7 --- /dev/null +++ b/src/APIexamples/locationuser3.json @@ -0,0 +1,36 @@ +{ + "LocationList": { + "noNamespaceSchemaLocation": "http://api.vasttrafik.se/v1/hafasRestLocation.xsd", + "servertime": "16:45", + "serverdate": "2020-12-09", + "StopLocation": [ + { + "name": "Guddeby, Kungälv", + "id": "9022014014751001", + "lat": "57.874665", + "lon": "11.903884", + "track": "A" + }, + { + "name": "Guddeby, Kungälv", + "id": "9021014014751000", + "lat": "57.874710", + "lon": "11.903929" + }, + { + "name": "Guddeby, Kungälv", + "id": "9022014014751002", + "lat": "57.874746", + "lon": "11.903965", + "track": "B" + }, + { + "name": "Stället, Kungälv", + "id": "9022014014744001", + "lat": "57.869784", + "lon": "11.904172", + "track": "A" + } + ] + } + } \ No newline at end of file diff --git a/src/APIexamples/locationuser4.json b/src/APIexamples/locationuser4.json new file mode 100644 index 0000000..d8f2fc4 --- /dev/null +++ b/src/APIexamples/locationuser4.json @@ -0,0 +1,35 @@ +{ + "LocationList": { + "noNamespaceSchemaLocation": "http://api.vasttrafik.se/v1/hafasRestLocation.xsd", + "servertime": "16:44", + "serverdate": "2020-12-09", + "StopLocation": [ + { + "name": "Skrämmenborg, Kungälv", + "id": "9021014014225000", + "lat": "57.863528", + "lon": "11.867406" + }, + { + "name": "Skrämmenborg, Kungälv", + "id": "9022014014225001", + "lat": "57.863528", + "lon": "11.867406", + "track": "A" + }, + { + "name": "Kuröd, Kungälv", + "id": "9022014014762002", + "lat": "57.856966", + "lon": "11.863774", + "track": "B" + }, + { + "name": "Kuröd, Kungälv", + "id": "9021014014762000", + "lat": "57.856831", + "lon": "11.864260" + } + ] + } + } \ No newline at end of file diff --git a/src/GlobalData.js b/src/GlobalData.js index 317501f..a076cb4 100644 --- a/src/GlobalData.js +++ b/src/GlobalData.js @@ -1,6 +1,7 @@ import User from './classes/User.js'; import Disruption from './classes/Disruption.js' -import Coordinates from "./classes/Coordinates.js"; +import Coordinates from './classes/Coordinates.js'; +import Stop from './classes/Stop.js' let globalData = { user: new User( @@ -10,6 +11,8 @@ let globalData = { "9022014014020001" ), disruption: new Disruption( + ), + stop: new Stop( ) }; diff --git a/src/classes/Stop.js b/src/classes/Stop.js index fa4f76e..f64b86c 100644 --- a/src/classes/Stop.js +++ b/src/classes/Stop.js @@ -7,8 +7,11 @@ */ class Stop { - constructor(name, locations, departures) { + constructor(name, id, lat, lon, locations, departures) { this.name = name; + this.id = id; + this.lat = lat; + this.lon = lon; this.locations = locations; this.departures = departures; } diff --git a/src/components/FindStops.js b/src/components/FindStops.js new file mode 100644 index 0000000..99e5bdc --- /dev/null +++ b/src/components/FindStops.js @@ -0,0 +1,41 @@ + +import globData from '../GlobalData.js'; + +import locationuser1 from '../APIexamples/locationuser1.json' +import locationuser2 from '../APIexamples/locationuser2.json' +import locationuser3 from '../APIexamples/locationuser3.json' +import locationuser4 from '../APIexamples/locationuser4.json' + +import Button from './Button.js'; +import disruptIcon from '../img/flash.svg'; + +class FindStops extends Button { + state = { + locations : "" + } + findStops = () => { + if(globData.user.deviceId === "1"){ + this.state.locations = locationuser1.StopLocation + }else if (globData.user.deviceId === "2"){ + this.state.locations = locationuser2.StopLocation + }else if (globData.user.deviceId === "3"){ + this.state.locations = locationuser3.StopLocation + }else if (globData.user.deviceId === "4"){ + this.state.locations = locationuser4.StopLocation + } + } + + render() { + return ( + <> + + + ); + } +} + + +export default FindStops; diff --git a/src/components/StopSelector.js b/src/components/StopSelector.js new file mode 100644 index 0000000..e69de29