@@ -22,18 +22,31 @@ import MobileDashboardView from './modules/Mobile/MobileDashboardView';
2222import { getUser } from './modules/User/actions' ;
2323import { stopSketch } from './modules/IDE/actions/ide' ;
2424import { userIsAuthenticated , userIsNotAuthenticated , userIsAuthorized } from './utils/auth' ;
25+ import ResponsiveForm from './modules/User/components/ResponsiveForm' ;
2526
2627const checkAuth = ( store ) => {
2728 store . dispatch ( getUser ( ) ) ;
2829} ;
2930
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 => (
3138 < MediaQuery minDeviceWidth = { 770 } >
32- { matches => ( ( matches && ( ! store || store . getState ( ) . editorAccessibility . forceDesktop ) )
39+ { matches => ( ( matches || ( store && store . getState ( ) . editorAccessibility . forceDesktop ) || ( ! mobileEnabled ( ) ) )
3340 ? < Fallback { ...props } />
3441 : < MobileComponent { ...props } /> ) }
3542 </ MediaQuery > ) ;
3643
44+ const responsiveForm = DesktopComponent => props => (
45+ < ResponsiveForm >
46+ < DesktopComponent { ...props } />
47+ </ ResponsiveForm >
48+ ) ;
49+
3750// TODO: This short-circuit seems unnecessary - using the mobile <Switch /> navigator (future) should prevent this from being called
3851const onRouteChange = ( store ) => {
3952 const path = window . location . pathname ;
@@ -42,41 +55,45 @@ const onRouteChange = (store) => {
4255 store . dispatch ( stopSketch ( ) ) ;
4356} ;
4457
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+ } ;
8198
8299export default routes ;
0 commit comments