Compare commits
16 Commits
aw-disrupt
...
we-Disrupt
Author | SHA1 | Date | |
---|---|---|---|
7c59fa2825 | |||
31263e919e | |||
d40420ad2b | |||
4ce76dbe90 | |||
051afedcc5 | |||
bff5a73c8c | |||
093199d0e0 | |||
25d66f9195 | |||
4e36270130 | |||
c36d6afea7 | |||
ff8a87c961 | |||
c3edd2d74f | |||
b324250c79 | |||
e35524fa19 | |||
521d3b2e63 | |||
3bc1ff9a1a |
35
README.md
35
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.
|
* ``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``.
|
* Ursprungspunkten för React är ``src/index.js``.
|
||||||
|
|
||||||
<!--
|
|
||||||
## Upplägg
|
## Upplägg
|
||||||
```mermaid
|
```mermaid
|
||||||
|
|
||||||
classDiagram
|
classDiagram
|
||||||
|
|
||||||
class User
|
class User
|
||||||
User : Subscription[] subs
|
User : String deviceId
|
||||||
User : Location loc
|
User : Coordinates location
|
||||||
|
User : nearbyStops()
|
||||||
|
|
||||||
class Line
|
class Coordinates
|
||||||
|
Coordinates : Float lon
|
||||||
|
Coordinates : Float lat
|
||||||
|
|
||||||
class Subscription
|
class Stop
|
||||||
Subscription : Line line
|
Stop : String name
|
||||||
|
Stop : Track[] locations
|
||||||
|
Stop : Departure[] departures
|
||||||
|
|
||||||
|
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",
|
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
|
||||||
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="
|
"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": {
|
"react-push-notification": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/react-push-notification/-/react-push-notification-1.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/react-push-notification/-/react-push-notification-1.3.0.tgz",
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
"react": "^17.0.1",
|
"react": "^17.0.1",
|
||||||
"react-axios": "^2.0.3",
|
"react-axios": "^2.0.3",
|
||||||
"react-dom": "^17.0.1",
|
"react-dom": "^17.0.1",
|
||||||
|
"react-native-push-notification": "^6.1.3",
|
||||||
"react-push-notification": "^1.3.0",
|
"react-push-notification": "^1.3.0",
|
||||||
"react-router-dom": "^5.2.0",
|
"react-router-dom": "^5.2.0",
|
||||||
"react-scripts": "4.0.0",
|
"react-scripts": "4.0.0",
|
||||||
|
@ -5,8 +5,9 @@ import React, { Component } from "react";
|
|||||||
import { BrowserRouter as Router, Route } from "react-router-dom";
|
import { BrowserRouter as Router, Route } from "react-router-dom";
|
||||||
|
|
||||||
import BottomMenu from "./components/BottomMenu.js";
|
import BottomMenu from "./components/BottomMenu.js";
|
||||||
import AccessToken from "./components/AccessToken.js";
|
import NearbyStation from "./components/NearbyStation.js";
|
||||||
import NearbyStation from "./components/NearbyStation";
|
import Disruption from "./components/Disruption.js";
|
||||||
|
import StationDisruption from "./components/StationDisruption.js";
|
||||||
|
|
||||||
import Tickets from "./components/pages/Tickets.js";
|
import Tickets from "./components/pages/Tickets.js";
|
||||||
import TicketsBuy from "./components/pages/TicketsBuy.js";
|
import TicketsBuy from "./components/pages/TicketsBuy.js";
|
||||||
@ -20,6 +21,8 @@ class App extends Component {
|
|||||||
return (
|
return (
|
||||||
<Router>
|
<Router>
|
||||||
<div className="App">
|
<div className="App">
|
||||||
|
<NearbyStation/>
|
||||||
|
<Disruption/>
|
||||||
<Route path="/" exact component={TicketsBuy} />
|
<Route path="/" exact component={TicketsBuy} />
|
||||||
<Route path="/tickets" exact component={Tickets} />
|
<Route path="/tickets" exact component={Tickets} />
|
||||||
<Route path="/ticketsBuy" exact component={TicketsBuy} />
|
<Route path="/ticketsBuy" exact component={TicketsBuy} />
|
||||||
|
12
src/GlobalData.js
Normal file
12
src/GlobalData.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import User from './classes/User.js';
|
||||||
|
import Coordinates from "./classes/Coordinates.js";
|
||||||
|
|
||||||
|
let globalData = {
|
||||||
|
user: new User(
|
||||||
|
"test",
|
||||||
|
"123",
|
||||||
|
new Coordinates()
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
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.
|
Denna klass är en modell för avgångar.
|
||||||
|
|
||||||
lineName : String (Linjenamnet)
|
lineName : String (Linjenamnet)
|
||||||
destination : String (Exempelvis "Mot Heden")
|
finalStop : Stop (Ändhållplats)
|
||||||
time : String (Avgångstid)
|
time : String (Avgångstid)
|
||||||
info : String (Trafikinformation)
|
trafficInfo : String (Trafikinformation)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Departure {
|
class Departure {
|
||||||
constructor(lineName, destination, time, info) {
|
constructor(lineName, finalStop, time, trafficInfo) {
|
||||||
this.lineName = lineName;
|
this.lineName = lineName;
|
||||||
this.destination = destination;
|
this.finalStop = finalStop;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
this.info = info;
|
this.trafficInfo = trafficInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
src/classes/Disruption.js
Normal file
24
src/classes/Disruption.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
Denna klass är en modell för störningar.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Disruption {
|
||||||
|
constructor(startTime, locations, departures) {
|
||||||
|
this.startTime = startTime;
|
||||||
|
this.affectedLines = affectedLines;
|
||||||
|
this.departures = departures;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 Disruption;
|
@ -2,7 +2,7 @@
|
|||||||
Denna klass är en modell för hållplatser.
|
Denna klass är en modell för hållplatser.
|
||||||
|
|
||||||
name : String (Hållplatsens namn)
|
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)
|
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;
|
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) {
|
||||||
|
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 {
|
class Button extends Component {
|
||||||
// Multiple onClick functions
|
// Multiple onClick functions
|
||||||
onClick = () => {
|
onClick = () => {
|
||||||
console.log(this.props.onClick);
|
|
||||||
|
|
||||||
if (this.props.onClick !== null
|
if (this.props.onClick !== null
|
||||||
&& this.props.onClick !== undefined) {
|
&& this.props.onClick !== undefined) {
|
||||||
if (Array.isArray(this.props.onClick)) {
|
if (Array.isArray(this.props.onClick)) {
|
||||||
@ -17,8 +15,6 @@ class Button extends Component {
|
|||||||
} else {
|
} else {
|
||||||
console.log("Error when parsing Button onClick functions.");
|
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,5 +1,6 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
|
|
||||||
|
import globalData from '../GlobalData.js';
|
||||||
import DisruptionButton from "./DisruptionButton.js";
|
import DisruptionButton from "./DisruptionButton.js";
|
||||||
import Popup from './Popup.js';
|
import Popup from './Popup.js';
|
||||||
import Button from './Button.js';
|
import Button from './Button.js';
|
||||||
@ -58,7 +59,7 @@ class NavigationDrawer extends Component {
|
|||||||
<div id="navDrawer" className={`${this.state.open ? "open" : ""}`}>
|
<div id="navDrawer" className={`${this.state.open ? "open" : ""}`}>
|
||||||
<header>
|
<header>
|
||||||
<img src={userIcon} alt="" />
|
<img src={userIcon} alt="" />
|
||||||
<span>Mitt konto</span>
|
<span>{globalData.user.name}</span>
|
||||||
<span>example@gmail.com</span>
|
<span>example@gmail.com</span>
|
||||||
</header>
|
</header>
|
||||||
<div id="navList">
|
<div id="navList">
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import AccessToken from '../classes/AccessToken';
|
||||||
|
import StopComponent from './StopComponent';
|
||||||
|
import Stop from '../classes/Stop';
|
||||||
|
|
||||||
class NearbyStation extends React.Component {
|
class NearbyStation extends React.Component {
|
||||||
state = {
|
state = {
|
||||||
@ -7,7 +10,7 @@ class NearbyStation extends React.Component {
|
|||||||
long: '12.0',
|
long: '12.0',
|
||||||
stops: [],
|
stops: [],
|
||||||
token: undefined,
|
token: undefined,
|
||||||
device: '123',
|
tokenClass: new AccessToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChangeLat = event => {
|
handleChangeLat = event => {
|
||||||
@ -18,20 +21,16 @@ class NearbyStation extends React.Component {
|
|||||||
this.setState({ long: event.target.value});
|
this.setState({ long: event.target.value});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChangeToken = event => {
|
|
||||||
this.setState({ token: event.target.value})
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSubmit = event => {
|
handleSubmit = event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
'Authorization': 'Bearer ' + this.state.token
|
'Authorization': 'Bearer ' + this.state.tokenClass.token
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('Attempted connection')
|
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 => {
|
.then(response => {
|
||||||
console.log(response.data.LocationList.StopLocation)
|
console.log(response.data.LocationList.StopLocation)
|
||||||
this.setState({
|
this.setState({
|
||||||
@ -52,10 +51,6 @@ class NearbyStation extends React.Component {
|
|||||||
Longitude coord:
|
Longitude coord:
|
||||||
<input type="text" name="long" onChange={this.handleChangeLong} />
|
<input type="text" name="long" onChange={this.handleChangeLong} />
|
||||||
</label>
|
</label>
|
||||||
<label>
|
|
||||||
Token:
|
|
||||||
<input type="text" name="token" onChange={this.handleChangeToken} />
|
|
||||||
</label>
|
|
||||||
<button type="submit">Stops</button>
|
<button type="submit">Stops</button>
|
||||||
</form>
|
</form>
|
||||||
<h1>
|
<h1>
|
||||||
@ -65,32 +60,11 @@ class NearbyStation extends React.Component {
|
|||||||
{this.state.long}
|
{this.state.long}
|
||||||
</h1>
|
</h1>
|
||||||
{this.state.stops.map((item) =>
|
{this.state.stops.map((item) =>
|
||||||
<div>
|
<StopComponent stop={item} />
|
||||||
<h1>
|
|
||||||
{item.name},
|
|
||||||
{item.id},
|
|
||||||
{item.lat},
|
|
||||||
{item.lon},
|
|
||||||
{item.track}
|
|
||||||
</h1>
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default NearbyStation
|
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
|
|
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 {
|
class TrafficEntry extends Component {
|
||||||
render() {
|
render() {
|
||||||
let trafficInfo = this.props.departure.info;
|
let trafficInfo = this.props.departure.trafficInfo;
|
||||||
let lineInterference = trafficInfo !== "" && trafficInfo !== null;
|
let lineInterference = trafficInfo !== "" && trafficInfo !== null && trafficInfo !== undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="trafficEntry">
|
<div className="trafficEntry">
|
||||||
@ -23,7 +23,7 @@ class TrafficEntry extends Component {
|
|||||||
<div>
|
<div>
|
||||||
<span className="lineName">{this.props.departure.lineName}</span>
|
<span className="lineName">{this.props.departure.lineName}</span>
|
||||||
<img src={busIcon} alt=""></img>
|
<img src={busIcon} alt=""></img>
|
||||||
<span className="destination">{this.props.departure.destination}</span>
|
<span className="destination">{this.props.departure.finalStop}</span>
|
||||||
</div>
|
</div>
|
||||||
{lineInterference &&
|
{lineInterference &&
|
||||||
<p>{trafficInfo} <u>Visa mer</u></p>
|
<p>{trafficInfo} <u>Visa mer</u></p>
|
||||||
|
Reference in New Issue
Block a user