Skip to content

Commit 3aebfb0

Browse files
authored
Merge pull request #119 from dymajo/react-native-web
New UI
2 parents 8200697 + f16c457 commit 3aebfb0

File tree

109 files changed

+14199
-11584
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+14199
-11584
lines changed

.babelrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"modules": false
77
}
88
],
9+
"stage-2",
910
"react"
1011
],
11-
"plugins": ["transform-class-properties"]
12-
}
12+
"plugins": ["lodash", "react-native-web"]
13+
}

dist/icons/cablecar.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/icons/close.svg

Lines changed: 4 additions & 0 deletions
Loading

dist/icons/locate-2.svg

Lines changed: 3 additions & 0 deletions
Loading

dist/icons/metlink.svg

Lines changed: 9 additions & 1 deletion
Loading

dist/icons/normal/bike-fill.svg

Lines changed: 10 additions & 0 deletions
Loading

dist/icons/normal/bike.svg

Lines changed: 28 additions & 0 deletions
Loading

js/app.jsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom'
3-
import { BrowserRouter } from 'react-router-dom'
4-
import { iOS } from './models/ios.js'
3+
import { Router } from 'react-router-dom'
54

6-
import Index from './views/index.jsx'
5+
import { UiStore } from './stores/uiStore.js'
76

8-
import injectTapEventPlugin from 'react-tap-event-plugin'
9-
injectTapEventPlugin()
7+
import Index from './views/shell/index.jsx'
108

119
import smoothscroll from 'smoothscroll-polyfill'
1210
smoothscroll.polyfill()
1311

1412
class App extends React.Component {
1513
render() {
1614
return (
17-
<BrowserRouter>
15+
<Router history={UiStore.customHistory}>
1816
<Index />
19-
</BrowserRouter>
17+
</Router>
2018
)
2119
}
2220
}
@@ -33,7 +31,7 @@ document.addEventListener('DOMContentLoaded', function(event) {
3331
let startApp = function() {
3432
window.defaultContent = [
3533
window.location.pathname,
36-
(document.querySelector('.default-container') || {}).innerHTML || null
34+
(document.querySelector('.default-container') || {}).innerHTML || null,
3735
]
3836
ReactDOM.render(<App />, document.getElementById('app'))
3937
}

js/data/lineData.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import local from '../../local'
2+
3+
export class LineData {
4+
constructor(props) {
5+
this.region = props.region || null
6+
this.line_id = props.line_id || null
7+
this.shape_id = props.shape_id || null
8+
this.trip_id = props.trip_id || null
9+
}
10+
getMeta() {
11+
return new Promise((resolve, reject) => {
12+
if (this.region === null || this.line_id === null) {
13+
return reject('Requires both region and line_id to be set.')
14+
}
15+
const line = encodeURIComponent(this.line_id)
16+
fetch(`${local.endpoint}/${this.region}/line/${line}`)
17+
.then(response => {
18+
response.json().then(data => {
19+
resolve(data)
20+
})
21+
})
22+
.catch(reject)
23+
})
24+
}
25+
getShape() {
26+
return new Promise((resolve, reject) => {
27+
if (this.region === null || this.shape_id === null) {
28+
return reject('Requires both region and shape_id to be set.')
29+
}
30+
const shape = encodeURIComponent(this.shape_id)
31+
fetch(`${local.endpoint}/${this.region}/shapejson/${shape}`)
32+
.then(response => {
33+
response.json().then(data => {
34+
const bounds = {
35+
lon_min: data.coordinates[0][0],
36+
lon_max: data.coordinates[0][0],
37+
lat_min: data.coordinates[0][1],
38+
lat_max: data.coordinates[0][1],
39+
}
40+
data.coordinates.forEach(item => {
41+
if (item[0] < bounds.lon_min) {
42+
bounds.lon_min = item[0]
43+
}
44+
if (item[0] > bounds.lon_max) {
45+
bounds.lon_max = item[0]
46+
}
47+
if (item[1] < bounds.lat_min) {
48+
bounds.lat_min = item[1]
49+
}
50+
if (item[1] > bounds.lat_max) {
51+
bounds.lat_max = item[1]
52+
}
53+
})
54+
data.bounds = bounds
55+
data.center =
56+
data.coordinates[Math.round(data.coordinates.length / 2)]
57+
resolve(data)
58+
})
59+
})
60+
.catch(reject)
61+
})
62+
}
63+
getStops() {
64+
return new Promise((resolve, reject) => {
65+
if (this.region === null) {
66+
return reject('Requires region to be set.')
67+
}
68+
69+
let url = `${local.endpoint}/${this.region}/stops/`
70+
if (this.trip_id !== null) {
71+
url += `trip/${encodeURIComponent(this.trip_id)}`
72+
} else if (this.shape_id !== null) {
73+
url += `shape/${encodeURIComponent(this.shape_id)}`
74+
} else {
75+
return reject('Requires shape_id or trip_id to be set.')
76+
}
77+
fetch(url)
78+
.then(response => {
79+
response.json().then(data => {
80+
resolve(data)
81+
})
82+
})
83+
.catch(reject)
84+
})
85+
}
86+
}

js/helpers/icon.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ route_type_map.set(5, 'cablecar')
1111
route_type_map.set(6, 'gondola')
1212
route_type_map.set(7, 'funicular')
1313
route_type_map.set(-1, 'parkingbuilding')
14+
route_type_map.set(-2, 'bike')
1415

1516
const style_map = {
16-
'normal': new Map(),
17+
normal: new Map(),
1718
'au-syd': new Map(),
1819
}
1920
style_map.normal.set('default', [30, 49])
@@ -22,11 +23,12 @@ style_map.normal.set('0-selection', [24, 24])
2223
style_map.normal.set('2-selection', [28, 28])
2324
style_map.normal.set('4-selection', [28, 28])
2425

25-
style_map.normal.set(-1, [28,28])
26-
style_map.normal.set(2,[28, 34])
27-
style_map.normal.set(3,[26, 32])
28-
style_map.normal.set(4,[28, 34])
29-
style_map.normal.set(5,[28, 34])
26+
style_map.normal.set(-1, [28, 28])
27+
style_map.normal.set(-2, [26, 32])
28+
style_map.normal.set(2, [28, 34])
29+
style_map.normal.set(3, [26, 32])
30+
style_map.normal.set(4, [28, 34])
31+
style_map.normal.set(5, [28, 34])
3032

3133
style_map['au-syd'].set('default', [30, 30])
3234
style_map['au-syd'].set(0, [40, 40])
@@ -39,7 +41,6 @@ style_map['au-syd'].set('2-selection', [40, 40])
3941
style_map['au-syd'].set('4-selection', [40, 40])
4042

4143
class iconhelper {
42-
4344
getClassName(variant, prefix) {
4445
if (variant !== null && prefix === 'normal') {
4546
return 'currentSelectionIcon larger'
@@ -59,20 +60,24 @@ class iconhelper {
5960
const icon = {}
6061
let variantfile = ''
6162
let filetype = '.svg'
62-
63+
6364
if (typeof style_map[prefix] === 'undefined') {
6465
prefix = 'normal'
6566
}
6667
if (prefix !== 'normal' && variant === 'selection') {
6768
variantfile = '-selection'
6869
}
6970

70-
71-
icon.iconUrl = '/icons/' + prefix + '/' + this.getFileName(route_type, prefix, variant) + variantfile + filetype
71+
icon.iconUrl =
72+
'/icons/' +
73+
prefix +
74+
'/' +
75+
this.getFileName(route_type, prefix, variant) +
76+
variantfile +
77+
filetype
7278

7379
icon.iconSize = this.getSize(route_type, prefix, variant)
7480

75-
7681
icon.className = this.getClassName(variant, prefix)
7782
return new Icon(icon)
7883
}
@@ -93,9 +98,9 @@ class iconhelper {
9398
}
9499
return style_map[prefix].get('default')
95100
}
96-
getRouteType(route_type){
101+
getRouteType(route_type) {
97102
return route_type_map.get(route_type)
98-
}
103+
}
99104
}
100105

101-
export default iconhelper
106+
export default iconhelper

0 commit comments

Comments
 (0)