Skip to content

Commit

Permalink
Add barrier for undefined props
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinBeczak committed Aug 10, 2023
1 parent d2d0792 commit 56a2d82
Showing 1 changed file with 38 additions and 36 deletions.
74 changes: 38 additions & 36 deletions src/hooks/UseMRProperties/UseMRProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,45 @@ import AsIdentifiableFeature
const useMRProperties = workspaceContext => {
const [properties, setProperties] = useState({})

useEffect(() => {
const mrProperties = {
'#mapZoom': workspaceContext['taskMapZoom'],
}

const task = workspaceContext['taskMapTask']
if (task) {
const primaryFeature =
AsIdentifiableFeature(AsMappableTask(task).normalizedGeometries().features[0])

mrProperties['#mrTaskId'] = task.id
mrProperties['#osmId'] = primaryFeature.osmId()
mrProperties['#osmType'] = primaryFeature.osmType()

//map the task specific properties to the workspace properties
const { properties } = primaryFeature;
if (properties) {
Object.keys(properties).map((key) => {
mrProperties[key] = properties[key];
return null;
});
if(workspaceContext){
useEffect(() => {
const mrProperties = {
'#mapZoom': workspaceContext['taskMapZoom'],
}
}

const mapBounds = workspaceContext['taskMapBounds']
if (mapBounds) {
mrProperties['#mapLat'] = mapBounds.getCenter().lat
mrProperties['#mapLon'] = mapBounds.getCenter().lng
mrProperties['#mapBBox'] = mapBounds.toBBoxString()
mrProperties['#mapWest'] = mapBounds.getWest()
mrProperties['#mapSouth'] = mapBounds.getSouth()
mrProperties['#mapEast'] = mapBounds.getEast()
mrProperties['#mapNorth'] = mapBounds.getNorth()
}

setProperties(mrProperties)
}, [workspaceContext])

const task = workspaceContext['taskMapTask']
if (task) {
const primaryFeature =
AsIdentifiableFeature(AsMappableTask(task).normalizedGeometries().features[0])

mrProperties['#mrTaskId'] = task.id
mrProperties['#osmId'] = primaryFeature.osmId()
mrProperties['#osmType'] = primaryFeature.osmType()

//map the task specific properties to the workspace properties
const { properties } = primaryFeature;
if (properties) {
Object.keys(properties).map((key) => {
mrProperties[key] = properties[key];
return null;
});
}
}

const mapBounds = workspaceContext['taskMapBounds']
if (mapBounds) {
mrProperties['#mapLat'] = mapBounds.getCenter().lat
mrProperties['#mapLon'] = mapBounds.getCenter().lng
mrProperties['#mapBBox'] = mapBounds.toBBoxString()
mrProperties['#mapWest'] = mapBounds.getWest()
mrProperties['#mapSouth'] = mapBounds.getSouth()
mrProperties['#mapEast'] = mapBounds.getEast()
mrProperties['#mapNorth'] = mapBounds.getNorth()
}

setProperties(mrProperties)
}, [workspaceContext])
}

return properties
}
Expand Down

0 comments on commit 56a2d82

Please sign in to comment.