Skip to content

Commit d3ee2b9

Browse files
author
heysep
committed
Refactor Gmap to meet eslint
1 parent 0c78abc commit d3ee2b9

File tree

1 file changed

+51
-70
lines changed

1 file changed

+51
-70
lines changed

client/components/Gmap.jsx

+51-70
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,77 @@
1-
import { default as React, Component } from "react";
2-
import { GoogleMapLoader, GoogleMap, InfoWindow, Marker } from "react-google-maps";
1+
import { default as React, Component } from 'react';
2+
import { GoogleMapLoader, GoogleMap, InfoWindow, Marker } from 'react-google-maps';
33

44
class Gmap extends Component {
55

66
constructor(props) {
77
super(props);
88
this.state = {
9-
// specify the center of the map
109
center: {
1110
lat: 37.784817,
12-
lng: -122.406358
13-
}
14-
15-
}
11+
lng: -122.406358,
12+
},
13+
};
1614
}
1715

1816
componentWillReceiveProps() {
1917
console.log('Received new props!');
2018
}
2119

22-
// this will close all other infoWindows except the user clicked on
20+
// Close all other infoWindows except the user clicked on
2321
closeOtherInfoWindows(socketIdToKeepOpen) {
24-
// iterate all the users markers
25-
{Object.keys(this.props.users).map((socketId, index) => {
26-
let marker = this.props.users[socketId];
27-
// if userIdToKeepOpen is not current marker
28-
if ( marker.showInfo && socketId !== socketIdToKeepOpen ) {
29-
// close the marker window
22+
Object.keys(this.props.users).forEach((socketId) => {
23+
const marker = this.props.users[socketId];
24+
if (marker.showInfo && socketId !== socketIdToKeepOpen) {
3025
console.log('Closing info window of:', socketId);
3126
this.handleMarkerClose(marker);
3227
}
33-
34-
}); //end the map over users object
35-
36-
}
28+
});
3729
}
3830

39-
handleMeetRequest(receiverId) {
31+
handleMeetRequest() {
4032
console.log('Sending meeting request from user.');
4133
// change state here for request sent
4234
}
4335

44-
//Toggle to 'true' to show InfoWindow and re-renders component
36+
// Toggle to 'true' to show InfoWindow and re-renders component
4537
handleMarkerClick(marker) {
4638
console.log('Inside handleMarkerClick');
4739
this.closeOtherInfoWindows(marker.socketId);
48-
marker.showInfo = true;
40+
const user = marker;
41+
user.showInfo = true;
4942
this.setState(this.state);
5043
}
5144

5245
handleMarkerClose(marker) {
53-
marker.showInfo = false;
46+
const user = marker;
47+
user.showInfo = false;
5448
this.setState(this.state);
5549
}
5650

5751
renderInfoWindow(ref, marker) {
5852
return (
59-
60-
//You can nest components inside of InfoWindow!
6153
<InfoWindow
6254
key={`${ref}_info_window`}
63-
onCloseclick={this.handleMarkerClose.bind(this, marker)} >
55+
onCloseclick={this.handleMarkerClose.bind(this, marker)}
56+
>
6457

65-
{
66-
<div className="markerInfoWindow">
58+
{<div className="markerInfoWindow">
6759
<div className="markerProfilePic">
68-
<img src={marker.image} />
60+
<img alt="" src={marker.image} />
6961
</div>
7062
<div className="markerName">{marker.name}</div>
7163
<div className="markerBio">{marker.bio}</div>
72-
<button className="buttonSendMeetReq" onClick={this.handleMeetRequest.bind(this, marker)}>Let's Meet</button>
64+
<button className="buttonSendMeetReq" onClick={this.handleMeetRequest.bind(this, marker)}>
65+
Let's Meet
66+
</button>
7367
</div>
7468
}
7569

7670
</InfoWindow>
77-
7871
);
79-
8072
}
8173

8274
render() {
83-
8475
return (
8576

8677
<GoogleMapLoader
@@ -90,57 +81,47 @@ class Gmap extends Component {
9081
style={{
9182
margin: 'auto',
9283
width: '600px',
93-
height: '600px'
94-
}} >
84+
height: '600px',
85+
}}
86+
>
9587
</div>
9688
}
9789
googleMapElement={
9890
<GoogleMap
9991
// google map options:
10092
center={this.state.center}
101-
// higher zoom level will reduce the area covered
10293
defaultZoom={14}
103-
ref='map'>
104-
105-
{Object.keys(this.props.users).map((socketId, index) =>
106-
{
107-
const marker = this.props.users[socketId];
108-
// used to reference the marker to for positioning the infowindow
109-
const ref = `marker_${socketId}`;
110-
return (
111-
// use the Marker component to render user as a marker on map
112-
<Marker
113-
key={socketId}
114-
ref={ref}
115-
position={{lat: marker.lat, lng: marker.lng}}
116-
onClick={this.handleMarkerClick.bind(this, marker)} >
117-
118-
{marker.showInfo ? this.renderInfoWindow(ref, marker) : null}
119-
</Marker>
120-
);
121-
122-
}) // end map over users here
123-
}
94+
ref="map"
95+
>
96+
97+
{Object.keys(this.props.users).map((socketId) => {
98+
const marker = this.props.users[socketId];
99+
// used to reference the marker for positioning the infowindow
100+
const ref = `marker_${socketId}`;
101+
return (
102+
// use the Marker component to render user as a marker on map
103+
<Marker
104+
key={socketId}
105+
ref={ref}
106+
position={{ lat: marker.lat, lng: marker.lng }}
107+
onClick={this.handleMarkerClick.bind(this, marker)}
108+
>
109+
{marker.showInfo ? this.renderInfoWindow(ref, marker) : null}
110+
</Marker>
111+
);
112+
}) // end map over users here
113+
}
124114

125115
</GoogleMap>
126116
}
127117

128-
/> //end of GoogleMapLoader
129-
118+
/> // end of GoogleMapLoader
130119
);
131-
132120
}
133121
}
134122

135-
export default Gmap;
136-
137-
138-
139-
140-
141-
142-
143-
144-
145-
123+
Gmap.propTypes = {
124+
users: React.PropTypes.object,
125+
};
146126

127+
export default Gmap;

0 commit comments

Comments
 (0)