Skip to content

Commit a2736e2

Browse files
committed
♻️ move responsive helper methods to utils/responsive.jsx
1 parent d17ce3c commit a2736e2

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

client/routes.jsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Route, IndexRoute } from 'react-router';
22
import React from 'react';
3-
import PropTypes from 'prop-types';
4-
import MediaQuery from 'react-responsive';
53

64
import App from './modules/App/App';
75
import IDEView from './modules/IDE/pages/IDEView';
@@ -22,31 +20,12 @@ import MobileDashboardView from './modules/Mobile/MobileDashboardView';
2220
import { getUser } from './modules/User/actions';
2321
import { stopSketch } from './modules/IDE/actions/ide';
2422
import { userIsAuthenticated, userIsNotAuthenticated, userIsAuthorized } from './utils/auth';
25-
import ResponsiveForm from './modules/User/components/ResponsiveForm';
23+
import { createMobileFirst, responsiveForm } from './utils/responsive';
2624

2725
const checkAuth = (store) => {
2826
store.dispatch(getUser());
2927
};
3028

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 => (
38-
<MediaQuery minDeviceWidth={770}>
39-
{matches => ((matches || (store && store.getState().editorAccessibility.forceDesktop) || (!mobileEnabled()))
40-
? <Fallback {...props} />
41-
: <MobileComponent {...props} />)}
42-
</MediaQuery>);
43-
44-
const responsiveForm = DesktopComponent => props => (
45-
<ResponsiveForm>
46-
<DesktopComponent {...props} />
47-
</ResponsiveForm>
48-
);
49-
5029
// TODO: This short-circuit seems unnecessary - using the mobile <Switch /> navigator (future) should prevent this from being called
5130
const onRouteChange = (store) => {
5231
const path = window.location.pathname;

client/utils/responsive.jsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import MediaQuery from 'react-responsive';
3+
import ResponsiveForm from '../modules/User/components/ResponsiveForm';
4+
5+
export const mobileEnabled = () => (window.process.env.MOBILE_ENABLED === true);
6+
7+
8+
/** createMobileFirst: Receives the store, and creates a function that chooses between two components,
9+
* aimed at mobile and desktop resolutions, respectively.
10+
* The created function returns a Component (props => jsx)
11+
*/
12+
export const createMobileFirst = store => (MobileComponent, Fallback) => props => (
13+
<MediaQuery minDeviceWidth={770}>
14+
{matches => ((matches || (store && store.getState().editorAccessibility.forceDesktop) || (!mobileEnabled()))
15+
? <Fallback {...props} />
16+
: <MobileComponent {...props} />)}
17+
</MediaQuery>);
18+
19+
export const responsiveForm = DesktopComponent => props => (
20+
<ResponsiveForm>
21+
<DesktopComponent {...props} />
22+
</ResponsiveForm>
23+
);

0 commit comments

Comments
 (0)