forked from HSLdevcom/digitransit-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
193 lines (187 loc) · 6.12 KB
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import PropTypes from 'prop-types';
import React from 'react';
import Relay from 'react-relay/classic';
import { Route } from 'react-router';
import IndexPage from './component/IndexPage';
import IndexPageMeta from './component/IndexPageMeta';
import Error404 from './component/404';
import TopLevel from './component/TopLevel';
import Title from './component/Title';
import scrollTop from './util/scroll';
import { PREFIX_ITINERARY_SUMMARY } from './util/path';
import { preparePlanParams } from './util/planParamUtil';
import { validateServiceTimeRange } from './util/timeUtils';
import { errorLoading, getDefault, loadRoute } from './util/routerUtils';
import getStopRoutes from './stopRoutes';
import routeRoutes from './routeRoutes';
const planQueries = {
plan: (Component, variables) => Relay.QL`
query {
viewer {
${Component.getFragment('plan', variables)}
}
}`,
serviceTimeRange: () => Relay.QL`query { serviceTimeRange }`,
};
export default config => {
const SummaryPageWrapper = ({ props, routerProps, element }) =>
props
? React.cloneElement(element, props)
: React.cloneElement(element, {
...routerProps,
...preparePlanParams(config)(routerProps.params, routerProps),
plan: { plan: {} },
serviceTimeRange: validateServiceTimeRange(), // use default range
loading: true,
});
SummaryPageWrapper.propTypes = {
props: PropTypes.object.isRequired,
routerProps: PropTypes.object.isRequired,
};
return (
<Route component={TopLevel}>
<Route
path="/styleguide"
getComponent={(location, cb) => {
import(/* webpackChunkName: "styleguide" */ './component/StyleGuidePage')
.then(loadRoute(cb))
.catch(errorLoading);
}}
/>
<Route
path="/styleguide/component/:componentName"
topBarOptions={{ hidden: true }}
getComponent={(location, cb) => {
import(/* webpackChunkName: "styleguide" */ './component/StyleGuidePage')
.then(loadRoute(cb))
.catch(errorLoading);
}}
/>
<Route
path="/suosikki/uusi"
getComponent={(location, cb) => {
import(/* webpackChunkName: "add-favourite" */ './component/AddFavouritePage')
.then(loadRoute(cb))
.catch(errorLoading);
}}
/>
{getStopRoutes()}
{getStopRoutes(true) /* terminals */}
{routeRoutes}
<Route
path={`/${PREFIX_ITINERARY_SUMMARY}/:from/:to`}
getComponents={(location, cb) => {
Promise.all([
import(/* webpackChunkName: "itinerary" */ './component/SummaryTitle').then(
getDefault,
),
import(/* webpackChunkName: "itinerary" */ './component/SummaryPage').then(
getDefault,
),
import(/* webpackChunkName: "itinerary" */ './component/SummaryPageMeta').then(
getDefault,
),
]).then(([title, content, meta]) =>
cb(null, { title, content, meta }),
);
}}
queries={{ content: planQueries }}
prepareParams={preparePlanParams(config)}
render={{ content: SummaryPageWrapper }}
>
<Route
path=":hash/tulosta"
getComponents={(location, cb) => {
import(/* webpackChunkName: "itinerary" */ './component/PrintableItinerary')
.then(content => cb(null, { content: content.default }))
.catch(errorLoading);
}}
printPage
>
<Route path="kartta" fullscreenMap />
</Route>
<Route
path=":hash"
getComponents={(location, cb) => {
Promise.all([
import(/* webpackChunkName: "itinerary" */ './component/ItineraryTab').then(
getDefault,
),
import(/* webpackChunkName: "itinerary" */ './component/ItineraryPageMap').then(
getDefault,
),
]).then(([content, map]) => cb(null, { content, map }));
}}
>
<Route path="kartta" fullscreenMap />
</Route>
</Route>
<Route
path="/suosikki/muokkaa/sijainti/:id"
getComponent={(location, cb) => {
import(/* webpackChunkName: "add-favourite" */ './component/AddFavouritePage')
.then(loadRoute(cb))
.catch(errorLoading);
}}
/>
<Route
path="/suosikki/muokkaa/pysakki/:id"
getComponent={(location, cb) => {
import(/* webpackChunkName: "add-favourite" */ './component/AddFavouritePage')
.then(loadRoute(cb))
.catch(errorLoading);
}}
/>
<Route
path="/tietoja-palvelusta"
getComponents={(location, cb) => {
Promise.all([
Promise.resolve(Title),
import(/* webpackChunkName: "about" */ './component/AboutPage').then(
getDefault,
),
]).then(([title, content]) => cb(null, { title, content }));
}}
/>
{!config.URL.API_URL.includes('/api.') && (
<Route
path="/admin"
getComponent={(location, cb) => {
import(/* webpackChunkName: "admin" */ './component/AdminPage')
.then(loadRoute(cb))
.catch(errorLoading);
}}
/>
)}
<Route path="/js/*" component={Error404} />
<Route path="/css/*" component={Error404} />
<Route path="/assets/*" component={Error404} />
<Route
path="/(:from)(/:to)(/:tab)"
topBarOptions={{ disableBackButton: true }}
components={{
title: Title,
content: IndexPage,
meta: IndexPageMeta,
}}
onEnter={scrollTop}
/>
<Route
path="/?mock"
topBarOptions={{ disableBackButton: true }}
components={{
title: Title,
content: IndexPage,
}}
/>
{/* For all the rest render 404 */}
<Route
path="*"
components={{
title: Title,
content: SummaryPageWrapper,
}}
/>
</Route>
);
};