Compare commits
27 Commits
aw-disrupt
...
we-select-
Author | SHA1 | Date | |
---|---|---|---|
2d2ec96533 | |||
3c0fc6fe1f | |||
c7517f185c | |||
d39f114d5c | |||
a0ff50ab23 | |||
ca1ca3884d | |||
ea2a18f3ad | |||
75b4ecc4ed | |||
3080359dcd | |||
3d7e6cf52f | |||
34f4b8af18 | |||
7c59fa2825 | |||
31263e919e | |||
d40420ad2b | |||
4ce76dbe90 | |||
051afedcc5 | |||
bff5a73c8c | |||
093199d0e0 | |||
25d66f9195 | |||
4e36270130 | |||
c36d6afea7 | |||
ff8a87c961 | |||
c3edd2d74f | |||
b324250c79 | |||
e35524fa19 | |||
521d3b2e63 | |||
3bc1ff9a1a |
39
README.md
39
README.md
@ -25,20 +25,37 @@ Tutorials för React går att hitta [här](https://www.youtube.com/playlist?list
|
||||
* ``public/index.html`` är den enda HTML-fil vi kommer ha i appen, detta eftersom vi bygger en s.k. SPA (Single Page Application). Man ändrar oftast inget i denna fil utöver möjligtvis innehållet i ``<head>``, detta eftersom React hanterar hela vårt UI.
|
||||
* Ursprungspunkten för React är ``src/index.js``.
|
||||
|
||||
<!--
|
||||
|
||||
## Upplägg
|
||||
``` mermaid
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
class User
|
||||
User : String deviceId
|
||||
User : Coordinates location
|
||||
User : nearbyStops()
|
||||
|
||||
class User
|
||||
User : Subscription[] subs
|
||||
User : Location loc
|
||||
class Coordinates
|
||||
Coordinates : Float lon
|
||||
Coordinates : Float lat
|
||||
|
||||
class Line
|
||||
class Stop
|
||||
Stop : String name
|
||||
Stop : Track[] locations
|
||||
Stop : Departure[] departures
|
||||
|
||||
class Subscription
|
||||
Subscription : Line line
|
||||
class Departure
|
||||
Departure : String lineName
|
||||
Departure : Stop finalStop
|
||||
Departure : String time
|
||||
Departure : String trafficInfo
|
||||
|
||||
```
|
||||
-->
|
||||
class Track
|
||||
Track : String name
|
||||
|
||||
|
||||
User <.. Coordinates
|
||||
User <.. Stop
|
||||
Stop <.. Departure
|
||||
Departure <.. Stop
|
||||
Stop <.. Track
|
||||
```
|
5
package-lock.json
generated
5
package-lock.json
generated
@ -12386,6 +12386,11 @@
|
||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
|
||||
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="
|
||||
},
|
||||
"react-native-push-notification": {
|
||||
"version": "6.1.3",
|
||||
"resolved": "https://registry.npmjs.org/react-native-push-notification/-/react-native-push-notification-6.1.3.tgz",
|
||||
"integrity": "sha512-qNbFCkObCXwSFQbK6hJyx1Bym1D7V4XM8iN2L6eL3GAdNLmeBTdLdx3mPbKJtuaDJ1+deniFTQ2rz6hU4ELOXA=="
|
||||
},
|
||||
"react-push-notification": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/react-push-notification/-/react-push-notification-1.3.0.tgz",
|
||||
|
@ -10,6 +10,7 @@
|
||||
"react": "^17.0.1",
|
||||
"react-axios": "^2.0.3",
|
||||
"react-dom": "^17.0.1",
|
||||
"react-native-push-notification": "^6.1.3",
|
||||
"react-push-notification": "^1.3.0",
|
||||
"react-router-dom": "^5.2.0",
|
||||
"react-scripts": "4.0.0",
|
||||
|
15
src/APIexamples/disruption1.json
Normal file
15
src/APIexamples/disruption1.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"situationNumber": "RT1",
|
||||
"severity":"normal",
|
||||
"title":"Stannar inte på dessa hållplatser",
|
||||
"affectedStopPoints":[
|
||||
{
|
||||
"gid": "9022014014020001",
|
||||
"name": "Ekelöv västra, Kungälv"
|
||||
},
|
||||
{
|
||||
"gid": "9022014014751001",
|
||||
"name": "Guddeby, Kungälv"
|
||||
}
|
||||
]
|
||||
}
|
11
src/APIexamples/disruption2.json
Normal file
11
src/APIexamples/disruption2.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"situationNumber": "RT2",
|
||||
"severity":"normal",
|
||||
"title":"Försening",
|
||||
"affectedStopPoints":[
|
||||
{
|
||||
"gid": "9021014014225000",
|
||||
"name": "Skrämmenborg, Kungälv"
|
||||
}
|
||||
]
|
||||
}
|
5
src/APIexamples/user1.json
Normal file
5
src/APIexamples/user1.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"name":"1",
|
||||
"deviceId":"1",
|
||||
"stoppointgid":"9022014014754001"
|
||||
}
|
5
src/APIexamples/user2.json
Normal file
5
src/APIexamples/user2.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"name":"2",
|
||||
"deviceId":"2",
|
||||
"stoppointgid":"9022014014020001"
|
||||
}
|
5
src/APIexamples/user3.json
Normal file
5
src/APIexamples/user3.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"name":"3",
|
||||
"deviceId":"3",
|
||||
"stoppointgid":"9022014014751001"
|
||||
}
|
5
src/APIexamples/user4.json
Normal file
5
src/APIexamples/user4.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"name":"4",
|
||||
"deviceId":"4",
|
||||
"stoppointgid":"9021014014225000"
|
||||
}
|
@ -5,8 +5,9 @@ import React, { Component } from "react";
|
||||
import { BrowserRouter as Router, Route } from "react-router-dom";
|
||||
|
||||
import BottomMenu from "./components/BottomMenu.js";
|
||||
import AccessToken from "./components/AccessToken.js";
|
||||
import NearbyStation from "./components/NearbyStation";
|
||||
import NearbyStation from "./components/NearbyStation.js";
|
||||
import Disruption from "./components/Disruption.js";
|
||||
import StationDisruption from "./components/StationDisruption.js";
|
||||
|
||||
import Tickets from "./components/pages/Tickets.js";
|
||||
import TicketsBuy from "./components/pages/TicketsBuy.js";
|
||||
|
16
src/GlobalData.js
Normal file
16
src/GlobalData.js
Normal file
@ -0,0 +1,16 @@
|
||||
import User from './classes/User.js';
|
||||
import Disruption from './classes/Disruption.js'
|
||||
import Coordinates from "./classes/Coordinates.js";
|
||||
|
||||
let globalData = {
|
||||
user: new User(
|
||||
"test",
|
||||
"123",
|
||||
new Coordinates(),
|
||||
"9022014014020001"
|
||||
),
|
||||
disruption: new Disruption(
|
||||
)
|
||||
};
|
||||
|
||||
export default globalData;
|
21
src/classes/AccessToken.js
Normal file
21
src/classes/AccessToken.js
Normal file
@ -0,0 +1,21 @@
|
||||
import axios from 'axios';
|
||||
|
||||
class AccessToken {
|
||||
credentials = 'NXR5N2d4bUFmUWxVSERIZG03a2dhcVh3SzVJYTp3cElPVVJuSkpjVHRPNnJPUlltWVlQcTR3WGth'
|
||||
device = '123'
|
||||
|
||||
constructor() {
|
||||
const headers = {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Authorization': 'Basic ' + this.credentials
|
||||
};
|
||||
|
||||
axios.post('https://api.vasttrafik.se/token','grant_type=client_credentials&scope=device_'+this.device, {headers} )
|
||||
.then(response => {
|
||||
console.log(response);
|
||||
this.token = response.data.access_token
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default AccessToken
|
15
src/classes/Coordinates.js
Normal file
15
src/classes/Coordinates.js
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
Denna klass är en modell för platskoordinater.
|
||||
|
||||
lon : Float (Longitud)
|
||||
lat : Float (Latitud)
|
||||
*/
|
||||
|
||||
class Coordinates {
|
||||
constructor(lon, lat) {
|
||||
this.lon = lon;
|
||||
this.lat = lat;
|
||||
}
|
||||
}
|
||||
|
||||
export default Coordinates;
|
@ -2,17 +2,17 @@
|
||||
Denna klass är en modell för avgångar.
|
||||
|
||||
lineName : String (Linjenamnet)
|
||||
destination : String (Exempelvis "Mot Heden")
|
||||
finalStop : Stop (Ändhållplats)
|
||||
time : String (Avgångstid)
|
||||
info : String (Trafikinformation)
|
||||
trafficInfo : String (Trafikinformation)
|
||||
*/
|
||||
|
||||
class Departure {
|
||||
constructor(lineName, destination, time, info) {
|
||||
constructor(lineName, finalStop, time, trafficInfo) {
|
||||
this.lineName = lineName;
|
||||
this.destination = destination;
|
||||
this.finalStop = finalStop;
|
||||
this.time = time;
|
||||
this.info = info;
|
||||
this.trafficInfo = trafficInfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
11
src/classes/Disruption.js
Normal file
11
src/classes/Disruption.js
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
class Disruption {
|
||||
constructor(situationNumber, severity, title, affectedStopPoints) {
|
||||
this.situationNumber = situationNumber;
|
||||
this.severity = severity;
|
||||
this.title = title;
|
||||
this.affectedStopPoints = affectedStopPoints;
|
||||
}
|
||||
}
|
||||
|
||||
export default Disruption;
|
@ -2,7 +2,7 @@
|
||||
Denna klass är en modell för hållplatser.
|
||||
|
||||
name : String (Hållplatsens namn)
|
||||
locations : String[] (Möjliga lägen)
|
||||
locations : Track[] (Möjliga lägen)
|
||||
departures : Departure[] (Avgångar från hållplatsen)
|
||||
*/
|
||||
|
||||
@ -14,4 +14,15 @@ class Stop {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Från västtrafiks api ett element i listan av hållplatser ser ut som följande
|
||||
"id": "string",
|
||||
"lon": "string",
|
||||
"idx": "string",
|
||||
"weight": "string",
|
||||
"name": "string",
|
||||
"track": "string",
|
||||
"lat": "string"
|
||||
*/
|
||||
|
||||
export default Stop;
|
13
src/classes/Track.js
Normal file
13
src/classes/Track.js
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
Denna klass är en modell för hållplatslägen, ex. "Läge A" eller "Spår 3".
|
||||
|
||||
name : String (Lägets namn)
|
||||
*/
|
||||
|
||||
class Track {
|
||||
constructor(name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
export default Track;
|
18
src/classes/User.js
Normal file
18
src/classes/User.js
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
Denna klass är en modell för användare.
|
||||
|
||||
name : String (Användarnamn)
|
||||
deviceId : Int (Enhetens ID)
|
||||
location : Coordinates (Användarens koordinater)
|
||||
*/
|
||||
|
||||
class User {
|
||||
constructor(name, deviceId, location, stoppointgid) {
|
||||
this.name = name;
|
||||
this.deviceId = deviceId;
|
||||
this.location = location;
|
||||
this.stoppointgid = stoppointgid;
|
||||
}
|
||||
}
|
||||
|
||||
export default User;
|
@ -1,65 +0,0 @@
|
||||
import React from 'react';
|
||||
import axios from 'axios';
|
||||
|
||||
var globToken = ''
|
||||
|
||||
const GetToken = () => {
|
||||
const vars = {
|
||||
credentials: 'NXR5N2d4bUFmUWxVSERIZG03a2dhcVh3SzVJYTp3cElPVVJuSkpjVHRPNnJPUlltWVlQcTR3WGth',
|
||||
token: undefined,
|
||||
device: '123',
|
||||
}
|
||||
|
||||
const headers = {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Authorization': 'Basic ' + vars.credentials
|
||||
};
|
||||
|
||||
axios.post('https://api.vasttrafik.se/token','grant_type=client_credentials&scope=device_'+vars.device, { headers })
|
||||
.then(response => {
|
||||
console.log(response);
|
||||
globToken = response.data.access_token
|
||||
});
|
||||
}
|
||||
|
||||
class AccessToken extends React.Component {
|
||||
state = {
|
||||
token: 'No Token',
|
||||
}
|
||||
|
||||
handleChange = event => {
|
||||
this.setState({ token: event.target.value});
|
||||
}
|
||||
|
||||
handleSubmit = event => {
|
||||
event.preventDefault();
|
||||
|
||||
this.setState({
|
||||
credentials: 'Attempting to send token'
|
||||
});
|
||||
GetToken();
|
||||
}
|
||||
|
||||
handleFetch = event => {
|
||||
event.preventDefault();
|
||||
this.setState({token: globToken})
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<form onSubmit={this.handleSubmit}>
|
||||
<button type="submit">Get Token</button>
|
||||
</form>
|
||||
<h1>
|
||||
{this.state.token}
|
||||
</h1>
|
||||
<form onSubmit={this.handleFetch}>
|
||||
<button type="submit">fetch</button>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default AccessToken
|
@ -6,8 +6,6 @@ import './css/Button.css';
|
||||
class Button extends Component {
|
||||
// Multiple onClick functions
|
||||
onClick = () => {
|
||||
console.log(this.props.onClick);
|
||||
|
||||
if (this.props.onClick !== null
|
||||
&& this.props.onClick !== undefined) {
|
||||
if (Array.isArray(this.props.onClick)) {
|
||||
@ -17,8 +15,6 @@ class Button extends Component {
|
||||
} else {
|
||||
console.log("Error when parsing Button onClick functions.");
|
||||
}
|
||||
} else {
|
||||
console.log("Error when parsing Button onClick functions.");
|
||||
}
|
||||
}
|
||||
|
||||
|
60
src/components/Disruption.js
Normal file
60
src/components/Disruption.js
Normal file
@ -0,0 +1,60 @@
|
||||
import React from 'react';
|
||||
import axios from 'axios';
|
||||
import AccessToken from '../classes/AccessToken'
|
||||
|
||||
class Diruption extends React.Component {
|
||||
state = {
|
||||
gid: '9022014005700002',
|
||||
disruptions: [],
|
||||
token: undefined,
|
||||
tokenClass: new AccessToken()
|
||||
}
|
||||
|
||||
handleChangeGid = event => {
|
||||
this.setState({ lat: event.target.value});
|
||||
}
|
||||
|
||||
handleSubmit = event => {
|
||||
event.preventDefault();
|
||||
|
||||
const headers = {
|
||||
'Authorization': 'Bearer ' + this.state.tokenClass.token
|
||||
};
|
||||
|
||||
console.log('Attempted connection')
|
||||
|
||||
axios.get('https://api.vasttrafik.se/ts/v1/traffic-situations/stoppoint/'+this.state.gid, { headers })
|
||||
//axios.get('https://api.vasttrafik.se/ts/v1/traffic-situations/stoppoint/9022014005700002', { headers })
|
||||
.then(response => {
|
||||
console.log(response)
|
||||
this.setState({
|
||||
disruptions: response.data
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<form onSubmit={this.handleSubmit}>
|
||||
<label>
|
||||
Stoppoint Gid:
|
||||
<input type="text" name="gid" onChange={this.handleChangeGid} />
|
||||
</label>
|
||||
<button type="submit">Find traffic disruptions</button>
|
||||
</form>
|
||||
<h1>
|
||||
{this.state.gid}
|
||||
</h1>
|
||||
{this.state.disruptions.map((item) =>
|
||||
<div>
|
||||
<h1>
|
||||
{item.description}
|
||||
</h1>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
export default Diruption
|
@ -1,11 +1,39 @@
|
||||
import addNotification from "react-push-notification";
|
||||
|
||||
import globData from '../GlobalData.js';
|
||||
|
||||
import ex1 from '../APIexamples/disruption1.json'
|
||||
import ex2 from '../APIexamples/disruption2.json'
|
||||
|
||||
import Button from './Button.js';
|
||||
import disruptIcon from '../img/flash.svg';
|
||||
|
||||
|
||||
class DisruptionButton extends Button {
|
||||
state = {
|
||||
jsonLocation: this.props.path,
|
||||
disruption: ""
|
||||
}
|
||||
|
||||
|
||||
genDisrupt = () => {
|
||||
this.state.disruption = ""
|
||||
if(this.state.jsonLocation === "ex1"){
|
||||
for (let stopPoint of ex1.affectedStopPoints) {
|
||||
if(stopPoint.gid === globData.user.stoppointgid){
|
||||
this.state.disruption = ex1
|
||||
}
|
||||
}
|
||||
} else if (this.state.jsonLocation === "ex2"){
|
||||
for (let stopPoint of ex2.affectedStopPoints) {
|
||||
if(stopPoint.gid === globData.user.stoppointgid){
|
||||
this.state.disruption = ex2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(this.state.disruption)
|
||||
globData.disruption = this.state.disruption
|
||||
|
||||
addNotification({
|
||||
title: "Warning",
|
||||
subtitle: "This is a subtitle",
|
||||
|
@ -1,6 +1,8 @@
|
||||
import React, { Component } from 'react';
|
||||
|
||||
import globalData from '../GlobalData.js';
|
||||
import DisruptionButton from "./DisruptionButton.js";
|
||||
import SelectUserButton from "./SelectUserButton.js"
|
||||
import Popup from './Popup.js';
|
||||
import Button from './Button.js';
|
||||
|
||||
@ -58,11 +60,16 @@ class NavigationDrawer extends Component {
|
||||
<div id="navDrawer" className={`${this.state.open ? "open" : ""}`}>
|
||||
<header>
|
||||
<img src={userIcon} alt="" />
|
||||
<span>Mitt konto</span>
|
||||
<span>{globalData.user.name}</span>
|
||||
<span>example@gmail.com</span>
|
||||
</header>
|
||||
<div id="navList">
|
||||
<DisruptionButton onClick={[this.showPopup, this.close]} />
|
||||
<SelectUserButton path={"user1"} username="user1"/>
|
||||
<SelectUserButton path={"user2"} username="user2"/>
|
||||
<SelectUserButton path={"user3"} username="user3"/>
|
||||
<SelectUserButton path={"user4"} username="user4"/>
|
||||
<DisruptionButton path={"ex1"} onClick={[this.showPopup, this.close]} />
|
||||
<DisruptionButton path={"ex2"} onClick={[this.showPopup, this.close]} />
|
||||
</div>
|
||||
<hr />
|
||||
<span id="version">Projektgrupp 3 - Utmaning 7</span>
|
||||
|
@ -1,5 +1,8 @@
|
||||
import React from 'react';
|
||||
import axios from 'axios';
|
||||
import AccessToken from '../classes/AccessToken';
|
||||
import StopComponent from './StopComponent';
|
||||
import Stop from '../classes/Stop';
|
||||
|
||||
class NearbyStation extends React.Component {
|
||||
state = {
|
||||
@ -7,7 +10,7 @@ class NearbyStation extends React.Component {
|
||||
long: '12.0',
|
||||
stops: [],
|
||||
token: undefined,
|
||||
device: '123',
|
||||
tokenClass: new AccessToken()
|
||||
}
|
||||
|
||||
handleChangeLat = event => {
|
||||
@ -18,20 +21,16 @@ class NearbyStation extends React.Component {
|
||||
this.setState({ long: event.target.value});
|
||||
}
|
||||
|
||||
handleChangeToken = event => {
|
||||
this.setState({ token: event.target.value})
|
||||
}
|
||||
|
||||
handleSubmit = event => {
|
||||
event.preventDefault();
|
||||
|
||||
const headers = {
|
||||
'Authorization': 'Bearer ' + this.state.token
|
||||
'Authorization': 'Bearer ' + this.state.tokenClass.token
|
||||
};
|
||||
|
||||
console.log('Attempted connection')
|
||||
|
||||
axios.get('https://api.vasttrafik.se/bin/rest.exe/v2/location.nearbystops?originCoordLat='+this.state.lat+'&originCoordLong='+this.state.long+'&maxNo=20&format=json', { headers })
|
||||
axios.get('https://api.vasttrafik.se/bin/rest.exe/v2/location.nearbystops?originCoordLat='+this.state.lat+'&originCoordLong='+this.state.long+'&maxNo=5&format=json', { headers })
|
||||
.then(response => {
|
||||
console.log(response.data.LocationList.StopLocation)
|
||||
this.setState({
|
||||
@ -52,10 +51,6 @@ class NearbyStation extends React.Component {
|
||||
Longitude coord:
|
||||
<input type="text" name="long" onChange={this.handleChangeLong} />
|
||||
</label>
|
||||
<label>
|
||||
Token:
|
||||
<input type="text" name="token" onChange={this.handleChangeToken} />
|
||||
</label>
|
||||
<button type="submit">Stops</button>
|
||||
</form>
|
||||
<h1>
|
||||
@ -65,32 +60,11 @@ class NearbyStation extends React.Component {
|
||||
{this.state.long}
|
||||
</h1>
|
||||
{this.state.stops.map((item) =>
|
||||
<div>
|
||||
<h1>
|
||||
{item.name},
|
||||
{item.id},
|
||||
{item.lat},
|
||||
{item.lon},
|
||||
{item.track}
|
||||
</h1>
|
||||
</div>
|
||||
<StopComponent stop={item} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default NearbyStation
|
||||
|
||||
//https://api.vasttrafik.se/bin/rest.exe/v2/location.nearbystops?originCoordLat=57.5987&originCoordLong=11.9454&maxNo=20&format=json
|
||||
|
||||
//https://api.vasttrafik.se/bin/rest.exe/v2/location.nearbystops
|
||||
|
||||
|
||||
//'https://reqres.in/api/articles'
|
||||
|
||||
//'https://api.vasttrafik.se/token'
|
||||
|
||||
//grant_type=client_credentials&scope=<device_id>
|
||||
|
||||
//BPvMjPidHckBtETZxr3dHP1rptQa
|
||||
//z5MFCS_wwmqprc0s4iLZWBAUJdga
|
36
src/components/SelectUserButton.js
Normal file
36
src/components/SelectUserButton.js
Normal file
@ -0,0 +1,36 @@
|
||||
|
||||
import globData from '../GlobalData.js';
|
||||
|
||||
import user1 from '../APIexamples/user1.json'
|
||||
import user2 from '../APIexamples/user2.json'
|
||||
import user3 from '../APIexamples/user3.json'
|
||||
import user4 from '../APIexamples/user4.json'
|
||||
|
||||
import Button from './Button.js';
|
||||
import disruptIcon from '../img/flash.svg';
|
||||
|
||||
class SelectUserButton extends Button {
|
||||
selectUser = () => {
|
||||
if(this.props.path === "user1"){
|
||||
globData.user = user1
|
||||
}else if (this.props.path === "user2"){
|
||||
globData.user = user2
|
||||
}else if (this.props.path === "user3"){
|
||||
globData.user = user3
|
||||
}else if (this.props.path === "user4"){
|
||||
globData.user = user4
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Button onClick={[this.selectUser]} className="disruptBtn">
|
||||
<img src={disruptIcon} alt="" />
|
||||
<span>{this.props.username}</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default SelectUserButton;
|
64
src/components/StationDisruption.js
Normal file
64
src/components/StationDisruption.js
Normal file
@ -0,0 +1,64 @@
|
||||
import React from 'react';
|
||||
import axios from 'axios';
|
||||
import AccessToken from '../classes/AccessToken'
|
||||
|
||||
class StationDisruption extends React.Component {
|
||||
state = {
|
||||
gid: '9022014005700002',
|
||||
lat: '57.7',
|
||||
long: '12.0',
|
||||
disruptions: [],
|
||||
token: undefined,
|
||||
tokenClass: new AccessToken()
|
||||
}
|
||||
|
||||
handleChangeGid = event => {
|
||||
this.setState({ lat: event.target.value});
|
||||
}
|
||||
|
||||
handleSubmit = event => {
|
||||
event.preventDefault();
|
||||
|
||||
const headers = {
|
||||
'Authorization': 'Bearer ' + this.state.tokenClass.token
|
||||
};
|
||||
|
||||
console.log('Attempted connection')
|
||||
axios.get('https://api.vasttrafik.se/bin/rest.exe/v2/location.nearbystops?originCoordLat='+this.state.lat+'&originCoordLong='+this.state.long+'&maxNo=5&format=json', { headers })
|
||||
.then(response => {
|
||||
console.log(response.data.LocationList.StopLocation)
|
||||
})
|
||||
axios.get('https://api.vasttrafik.se/ts/v1/traffic-situations/stoppoint/'+this.state.gid, { headers })
|
||||
.then(response => {
|
||||
console.log(response)
|
||||
this.setState({
|
||||
disruptions: response.data
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<form onSubmit={this.handleSubmit}>
|
||||
<label>
|
||||
Stoppoint Gid:
|
||||
<input type="text" name="gid" onChange={this.handleChangeGid} />
|
||||
</label>
|
||||
<button type="submit">Find traffic disruptions</button>
|
||||
</form>
|
||||
<h1>
|
||||
{this.state.gid}
|
||||
</h1>
|
||||
{this.state.disruptions.map((item) =>
|
||||
<div>
|
||||
<h1>
|
||||
{item.description}
|
||||
</h1>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
export default StationDisruption
|
19
src/components/StopComponent.js
Normal file
19
src/components/StopComponent.js
Normal file
@ -0,0 +1,19 @@
|
||||
import React, {Component} from 'react';
|
||||
|
||||
class StopComponent extends Component {
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<h1>
|
||||
{this.props.stop.name},
|
||||
{this.props.stop.id},
|
||||
{this.props.stop.lat},
|
||||
{this.props.stop.lon},
|
||||
{this.props.stop.track}
|
||||
</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
// TODO Add css
|
||||
export default StopComponent
|
@ -7,8 +7,8 @@ import warningIcon from '../img/warning.svg';
|
||||
|
||||
class TrafficEntry extends Component {
|
||||
render() {
|
||||
let trafficInfo = this.props.departure.info;
|
||||
let lineInterference = trafficInfo !== "" && trafficInfo !== null;
|
||||
let trafficInfo = this.props.departure.trafficInfo;
|
||||
let lineInterference = trafficInfo !== "" && trafficInfo !== null && trafficInfo !== undefined;
|
||||
|
||||
return (
|
||||
<div className="trafficEntry">
|
||||
@ -23,7 +23,7 @@ class TrafficEntry extends Component {
|
||||
<div>
|
||||
<span className="lineName">{this.props.departure.lineName}</span>
|
||||
<img src={busIcon} alt=""></img>
|
||||
<span className="destination">{this.props.departure.destination}</span>
|
||||
<span className="destination">{this.props.departure.finalStop}</span>
|
||||
</div>
|
||||
{lineInterference &&
|
||||
<p>{trafficInfo} <u>Visa mer</u></p>
|
||||
|
@ -11,33 +11,33 @@ import Departure from "../../classes/Departure.js";
|
||||
|
||||
|
||||
class TrafficInfo extends Component {
|
||||
render() {
|
||||
let testStop = new Stop(
|
||||
"Lemmingsgatan",
|
||||
["Läge A", "Läge B", "Läge C"],
|
||||
[
|
||||
new Departure(
|
||||
"519",
|
||||
"Mot Heden",
|
||||
"11:59",
|
||||
"Trafikolycka vid Partille Centrum."
|
||||
),
|
||||
new Departure("58", "Mot Västra Eriksberg", "12:07"),
|
||||
]
|
||||
);
|
||||
render() {
|
||||
let testStop = new Stop(
|
||||
"Lemmingsgatan",
|
||||
["Läge A", "Läge B", "Läge C"],
|
||||
[
|
||||
new Departure(
|
||||
"519",
|
||||
"Mot Heden",
|
||||
"11:59",
|
||||
"Trafikolycka vid Partille Centrum."
|
||||
),
|
||||
new Departure("58", "Mot Västra Eriksberg", "12:07"),
|
||||
]
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header title="Trafikinfo" />
|
||||
<TopMenu>
|
||||
<StopTitle stop={testStop} />
|
||||
</TopMenu>
|
||||
<MainArea>
|
||||
<TrafficList departures={testStop.departures} />
|
||||
</MainArea>
|
||||
</>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<Header title="Trafikinfo" />
|
||||
<TopMenu>
|
||||
<StopTitle stop={testStop} />
|
||||
</TopMenu>
|
||||
<MainArea>
|
||||
<TrafficList departures={testStop.departures} />
|
||||
</MainArea>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default TrafficInfo;
|
||||
|
Reference in New Issue
Block a user