@@ -22,18 +22,31 @@ import MobileDashboardView from './modules/Mobile/MobileDashboardView';
22
22
import { getUser } from './modules/User/actions' ;
23
23
import { stopSketch } from './modules/IDE/actions/ide' ;
24
24
import { userIsAuthenticated , userIsNotAuthenticated , userIsAuthorized } from './utils/auth' ;
25
+ import ResponsiveForm from './modules/User/components/ResponsiveForm' ;
25
26
26
27
const checkAuth = ( store ) => {
27
28
store . dispatch ( getUser ( ) ) ;
28
29
} ;
29
30
30
- const mobileFirst = ( MobileComponent , Fallback , store ) => props => (
31
+ const mobileEnabled = ( ) => ( window . process . env . MOBILE_ENABLED === true ) ;
32
+
33
+ /** createMobileFirst: Receives the store, and creates a function that chooses between two components,
34
+ * aimed at mobile and desktop resolutions, respectively.
35
+ * The created function returns a Component (props => jsx)
36
+ */
37
+ const createMobileFirst = store => ( MobileComponent , Fallback ) => props => (
31
38
< MediaQuery minDeviceWidth = { 770 } >
32
- { matches => ( ( matches && ( ! store || store . getState ( ) . editorAccessibility . forceDesktop ) )
39
+ { matches => ( ( matches || ( store && store . getState ( ) . editorAccessibility . forceDesktop ) || ( ! mobileEnabled ( ) ) )
33
40
? < Fallback { ...props } />
34
41
: < MobileComponent { ...props } /> ) }
35
42
</ MediaQuery > ) ;
36
43
44
+ const responsiveForm = DesktopComponent => props => (
45
+ < ResponsiveForm >
46
+ < DesktopComponent { ...props } />
47
+ </ ResponsiveForm >
48
+ ) ;
49
+
37
50
// TODO: This short-circuit seems unnecessary - using the mobile <Switch /> navigator (future) should prevent this from being called
38
51
const onRouteChange = ( store ) => {
39
52
const path = window . location . pathname ;
@@ -42,41 +55,45 @@ const onRouteChange = (store) => {
42
55
store . dispatch ( stopSketch ( ) ) ;
43
56
} ;
44
57
45
- const routes = store => (
46
- < Route path = "/" component = { App } onChange = { ( ) => { onRouteChange ( store ) ; } } >
47
- < IndexRoute onEnter = { checkAuth ( store ) } component = { mobileFirst ( MobileIDEView , IDEView , store ) } />
48
-
49
- < Route path = "/login" component = { userIsNotAuthenticated ( LoginView ) } />
50
- < Route path = "/signup" component = { userIsNotAuthenticated ( SignupView ) } />
51
- < Route path = "/reset-password" component = { userIsNotAuthenticated ( ResetPasswordView ) } />
52
- < Route path = "/verify" component = { EmailVerificationView } />
53
- < Route
54
- path = "/reset-password/:reset_password_token"
55
- component = { NewPasswordView }
56
- />
57
- < Route path = "/projects/:project_id" component = { IDEView } />
58
- < Route path = "/:username/full/:project_id" component = { FullView } />
59
- < Route path = "/full/:project_id" component = { FullView } />
60
-
61
- < Route path = "/:username/assets" component = { userIsAuthenticated ( userIsAuthorized ( mobileFirst ( MobileDashboardView , DashboardView ) ) ) } />
62
- < Route path = "/:username/sketches" component = { mobileFirst ( MobileDashboardView , DashboardView ) } />
63
- < Route path = "/:username/sketches/:project_id" component = { mobileFirst ( MobileIDEView , IDEView ) } />
64
- < Route path = "/:username/sketches/:project_id/add-to-collection" component = { mobileFirst ( MobileIDEView , IDEView ) } />
65
- < Route path = "/:username/collections" component = { mobileFirst ( MobileDashboardView , DashboardView ) } />
66
-
67
- < Route path = "/:username/collections/create" component = { DashboardView } />
68
- < Route path = "/:username/collections/:collection_id" component = { CollectionView } />
69
-
70
- < Route path = "/sketches" component = { createRedirectWithUsername ( '/:username/sketches' ) } />
71
- < Route path = "/assets" component = { createRedirectWithUsername ( '/:username/assets' ) } />
72
- < Route path = "/account" component = { userIsAuthenticated ( AccountView ) } />
73
- < Route path = "/about" component = { IDEView } />
74
-
75
- { /* Mobile-only Routes */ }
76
- < Route path = "/preview" component = { MobileSketchView } />
77
- < Route path = "/preferences" component = { MobilePreferences } />
78
-
79
- </ Route >
80
- ) ;
58
+ const routes = ( store ) => {
59
+ const mobileFirst = createMobileFirst ( store ) ;
60
+
61
+ return (
62
+ < Route path = "/" component = { App } onChange = { ( ) => { onRouteChange ( store ) ; } } >
63
+ < IndexRoute onEnter = { checkAuth ( store ) } component = { mobileFirst ( MobileIDEView , IDEView ) } />
64
+
65
+ < Route path = "/login" component = { userIsNotAuthenticated ( mobileFirst ( responsiveForm ( LoginView ) , LoginView ) ) } />
66
+ < Route path = "/signup" component = { userIsNotAuthenticated ( mobileFirst ( responsiveForm ( SignupView ) , SignupView ) ) } />
67
+ < Route path = "/reset-password" component = { userIsNotAuthenticated ( ResetPasswordView ) } />
68
+ < Route path = "/verify" component = { EmailVerificationView } />
69
+ < Route
70
+ path = "/reset-password/:reset_password_token"
71
+ component = { NewPasswordView }
72
+ />
73
+ < Route path = "/projects/:project_id" component = { IDEView } />
74
+ < Route path = "/:username/full/:project_id" component = { FullView } />
75
+ < Route path = "/full/:project_id" component = { FullView } />
76
+
77
+ < Route path = "/:username/assets" component = { userIsAuthenticated ( userIsAuthorized ( mobileFirst ( MobileDashboardView , DashboardView ) ) ) } />
78
+ < Route path = "/:username/sketches" component = { mobileFirst ( MobileDashboardView , DashboardView ) } />
79
+ < Route path = "/:username/sketches/:project_id" component = { mobileFirst ( MobileIDEView , IDEView ) } />
80
+ < Route path = "/:username/sketches/:project_id/add-to-collection" component = { mobileFirst ( MobileIDEView , IDEView ) } />
81
+ < Route path = "/:username/collections" component = { mobileFirst ( MobileDashboardView , DashboardView ) } />
82
+
83
+ < Route path = "/:username/collections/create" component = { DashboardView } />
84
+ < Route path = "/:username/collections/:collection_id" component = { CollectionView } />
85
+
86
+ < Route path = "/sketches" component = { createRedirectWithUsername ( '/:username/sketches' ) } />
87
+ < Route path = "/assets" component = { createRedirectWithUsername ( '/:username/assets' ) } />
88
+ < Route path = "/account" component = { userIsAuthenticated ( AccountView ) } />
89
+ < Route path = "/about" component = { IDEView } />
90
+
91
+ { /* Mobile-only Routes */ }
92
+ < Route path = "/preview" component = { MobileSketchView } />
93
+ < Route path = "/preferences" component = { MobilePreferences } />
94
+
95
+ </ Route >
96
+ ) ;
97
+ } ;
81
98
82
99
export default routes ;
0 commit comments