Skip to content

Commit 83c9209

Browse files
author
riteshsangwan
committed
move constants to config
1 parent 9c52324 commit 83c9209

File tree

5 files changed

+13
-19
lines changed

5 files changed

+13
-19
lines changed

src/config/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ module.exports = {
1212
AUTH0_CLIENT_ID: process.env.REACT_APP_AUTH0_CLIENT_ID || 'h7p6V93Shau3SSvqGrl6V4xrATlkrVGm',
1313
AUTH0_CLIENT_DOMAIN: process.env.REACT_APP_AUTH0_CLIENT_DOMAIN || 'spanhawk.auth0.com',
1414
AUTH0_CALLBACK: 'http://localhost:3000',
15+
REGION_TYPES: {
16+
POINT: 'Point',
17+
POLYGON: 'Polygon',
18+
},
19+
USER_LOCATION_KEY: 'ul',
1520
};

src/layouts/CoreLayout/CoreLayout.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import Footer from 'components/Footer';
77
import styles from './CoreLayout.scss';
88
import {userLocationUpdateAction} from '../../store/modules/global';
99
import _ from 'lodash';
10-
11-
const USER_LOCATION_KEY = 'ul';
10+
import config from '../../config';
1211

1312
class CoreLayout extends React.Component {
1413

@@ -32,7 +31,7 @@ class CoreLayout extends React.Component {
3231
requestUserLocation() {
3332
const {onUserLocationUpdate} = this.props;
3433
// don't request the permission everytime and use caching
35-
const cachedLocation = localStorage.getItem(USER_LOCATION_KEY);
34+
const cachedLocation = localStorage.getItem(config.USER_LOCATION_KEY);
3635
// just to be extra safe here as a user can manipulate the content of local storage
3736
if (cachedLocation && _.has(cachedLocation, 'lat') && _.has(cachedLocation, 'lng')) {
3837
onUserLocationUpdate(cachedLocation);

src/routes/MissionPlanner/components/MissionMap/MissionMap.jsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import NoFlyZone from 'components/NoFlyZone';
66
import Rtfz from '../Rtfz';
77
import {GOOGLE_MAPS_BOUNDS_TIMEOUT} from 'Const';
88
import styles from './MissionMap.scss';
9+
import config from '../../../../config';
910

1011
// default center location for mission Planner
1112
const mapConfig = {
@@ -28,11 +29,6 @@ const polylineConfig = {
2829
},
2930
};
3031

31-
const types = {
32-
point: 'Point',
33-
polygon: 'Polygon',
34-
};
35-
3632
export const MissionGoogleMap = withGoogleMap((props) => (
3733
<GoogleMap
3834
{... mapConfig}
@@ -122,9 +118,9 @@ export class MissionMap extends Component {
122118
bounds = new google.maps.LatLngBounds();
123119
// bounds for rtfzs
124120
rtfzs.forEach((rtfz) => {
125-
if (rtfz.location.type === types.point) {
121+
if (rtfz.location.type === config.REGION_TYPES.POINT) {
126122
bounds.extend({lat: rtfz.location.coordinates[1], lng: rtfz.location.coordinates[0]});
127-
} else if (rtfz.location.type === types.polygon) {
123+
} else if (rtfz.location.type === config.REGION_TYPES.POLYGON) {
128124
rtfz.location.coordinates.forEach((coor) => {
129125
coor.forEach((point) => {
130126
bounds.extend({lat: point[1], lng: point[0]});

src/routes/MissionPlanner/components/Rtfz/Rtfz.jsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import React, {PropTypes} from 'react';
22
import {Marker, Polygon} from 'react-google-maps';
3-
4-
// define the type of region to fly zones
5-
const types = {
6-
point: 'Point',
7-
polygon: 'Polygon',
8-
};
3+
import config from '../../../../config';
94

105
export const Rtfz = ({zone}) => {
11-
if (zone.location.type === types.point) {
6+
if (zone.location.type === config.REGION_TYPES.POINT) {
127
return (
138
<Marker
149
options={{

src/store/modules/global.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const LOGIN_REDIRECT = {
2323

2424
const LOGOUT_ACTION = 'LOGOUT_ACTION';
2525
const USER_INFO_KEY = 'userInfo';
26-
const USER_LOCATION_KEY = 'ul';
2726

2827
// ------------------------------------
2928
// Actions
@@ -88,7 +87,7 @@ export const logoutAction = () => (dispatch) => {
8887

8988
export const userLocationUpdateAction = (location) => (dispatch) => {
9089
// cache the user location in localstorage
91-
localStorage.setItem(USER_LOCATION_KEY, JSON.stringify(location));
90+
localStorage.setItem(config.USER_LOCATION_KEY, JSON.stringify(location));
9291
dispatch({type: USER_LOCATION_UPDATE, payload: {location}});
9392
};
9493

0 commit comments

Comments
 (0)