Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
whats-open-web
Commits
90366827
Commit
90366827
authored
May 10, 2018
by
Andrew Hrdy
Browse files
The location array only generates once instead of every prop update in FacilitiesMap
parent
d1328022
Pipeline
#2443
passed with stages
in 2 minutes and 1 second
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/components/FacilitiesMap.js
View file @
90366827
...
...
@@ -6,6 +6,7 @@ import {FormControl} from 'material-ui/Form';
import
{
getMaxBounds
,
getCenterOfCampusRegion
}
from
'
../utils/mapboxUtils
'
;
import
mapboxgl
from
'
mapbox-gl
'
;
import
{
Typography
}
from
'
material-ui
'
;
import
{
removeBrackets
}
from
'
../utils/nameUtils
'
;
const
mapboxToken
=
'
pk.eyJ1IjoibWR1ZmZ5OCIsImEiOiJjaXk2a2lxODQwMDdyMnZzYTdyb3M4ZTloIn0.mSocl7zUnZBO6-CV9cvmnA
'
;
...
...
@@ -31,6 +32,13 @@ class FacilitiesMap extends React.Component {
const
facilityLocationExists
=
facility
&&
facility
.
facility_location
&&
facility
.
facility_location
.
campus_region
===
campusRegion
;
/**
* facilityLocations is an array of the type:
* {
* location: {}
* facilities: [{}, {}, ...]
* }
*/
this
.
state
=
{
maxBounds
:
getMaxBounds
(
campusRegion
),
campusRegion
:
campusRegion
,
...
...
@@ -43,11 +51,14 @@ class FacilitiesMap extends React.Component {
}
componentWillReceiveProps
(
nextProps
)
{
const
{
facility
}
=
nextProps
;
const
{
facility
,
facilities
}
=
nextProps
;
const
campusRegion
=
facility
&&
facility
.
facility_location
?
facility
.
facility_location
.
campus_region
:
'
fairfax
'
;
this
.
changeRegion
(
campusRegion
,
facility
);
this
.
generateLocationArray
(
nextProps
.
facilities
);
if
(
this
.
state
.
facilityLocations
.
length
===
0
)
{
this
.
generateLocationArray
(
facilities
);
}
}
changeRegion
=
(
campusRegion
,
facility
)
=>
{
...
...
@@ -61,7 +72,7 @@ class FacilitiesMap extends React.Component {
maxBounds
:
getMaxBounds
(
campusRegion
),
campusRegion
:
campusRegion
,
center
:
facilityLocationExists
?
facility
.
facility_location
.
coordinate_location
.
coordinates
:
getCenterOfCampusRegion
(
campusRegion
),
zoom
:
facilityLocationExists
?
[
17
]
:
[
0
]
,
zoom
:
facilityLocationExists
?
[
17
]
:
[
0
]
});
};
...
...
@@ -88,6 +99,7 @@ class FacilitiesMap extends React.Component {
selectLocation
=
(
location
)
=>
{
const
{
interactive
=
true
}
=
this
.
props
;
const
oldSelectedLocation
=
this
.
state
.
selectedLocation
;
const
oldZoom
=
this
.
state
.
zoom
;
if
(
!
interactive
)
{
return
;
...
...
@@ -96,7 +108,7 @@ class FacilitiesMap extends React.Component {
this
.
setState
({
selectedLocation
:
oldSelectedLocation
!==
location
?
location
:
null
,
center
:
location
&&
location
.
location
.
coordinate_location
.
coordinates
,
zoom
:
[
17
]
zoom
:
oldSelectedLocation
!==
location
?
[
17
]
:
oldZoom
});
}
...
...
@@ -175,7 +187,7 @@ class FacilitiesMap extends React.Component {
{
selectedLocation
.
facilities
.
map
((
facility
)
=>
{
return
(
<
li
key
=
{
facility
.
slug
}
>
<
Typography
type
=
"
caption
"
>
{
facility
.
facility_name
}
<
/Typography
>
<
Typography
type
=
"
caption
"
>
{
removeBrackets
(
facility
.
facility_name
)
}
<
/Typography
>
<
/li
>
);
})}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment