diff --git a/src/components/LayerMap.js b/src/components/LayerMap.js
index 14dc537..b7475d7 100644
--- a/src/components/LayerMap.js
+++ b/src/components/LayerMap.js
@@ -44,6 +44,10 @@ import tel_m3 from '../assets/img/map/cluster/tellers/m3.png';
import tel_m4 from '../assets/img/map/cluster/tellers/m4.png';
import tel_m5 from '../assets/img/map/cluster/tellers/m5.png';
+import { addProtocol, getProtocol } from '../utils/url';
+
+import { WHICH_OPTIONS } from '../utils/constants';
+
// List of countries
const countries = Countries();
@@ -59,8 +63,6 @@ const propTypes = {
showControls: PropTypes.bool
};
-
-
/**
* This object sets default values to the optional props.
*/
@@ -308,10 +310,27 @@ CustomLayerMap.propTypes = propTypes;
// Assign default values to the optional props
CustomLayerMap.defaultProps = defaultProps;
-// Type checking the props of the component
-CustomLayerMap.propTypes = propTypes;
-// Assign default values to the optional props
-CustomLayerMap.defaultProps = defaultProps;
+/**
+ * This object is used for type checking the props of the component.
+ */
+const propTypesLayerMap = {
+ ambassadorsLayer: PropTypes.bool,
+ merchantsLayer: PropTypes.bool,
+ showControls: PropTypes.bool,
+ mapHeight: PropTypes.string,
+ ambassadors: PropTypes.array,
+ merchants: PropTypes.array,
+ tellers: PropTypes.array,
+};
+
+/**
+ * This object sets default values to the optional props.
+ */
+const defaultPropsLayerMap = {
+ ambassadors: null,
+ merchants: null,
+ tellers: null
+};
class LayerMap extends Component {
constructor(props) {
@@ -330,9 +349,22 @@ class LayerMap extends Component {
* @description Lifecycle event handler called just after the App loads into the DOM.
*/
UNSAFE_componentWillMount() {
- this.getAmbassadors();
- this.getMerchants();
- this.getTellers();
+ this.updateMarkers();
+ }
+
+ // Update markers based if props are informed
+ updateMarkers() {
+ if(!this.props.ambassadors) {
+ this.getAmbassadors();
+ }
+
+ if(!this.props.merchants) {
+ this.getMerchants();
+ }
+
+ if (!this.props.tellers) {
+ this.getTellers();
+ }
}
fillResults(result) {
@@ -496,25 +528,53 @@ class LayerMap extends Component {
if(tellers.country !== undefined) tellers.country = countries.getName(tellers.country);
});
- const markers = result.data.map(merchant => {
- const infoDescription =
-
Address: {merchant.address}
- {(merchant.phone) && (
Phone: {merchant.phone}
)}
- {(merchant.telegram) && (
)}
- {(merchant.url) && (
)}
-
;
+ const markers = result.data.map(teller => {
+ if(teller.telegram){
+ teller.telegram_original = teller.telegram;
+ teller.telegram = {
+ searchText: teller.telegram_original,
+ value: (
+ {teller.telegram}
+ )
+ };
+ }
+ const which = WHICH_OPTIONS.filter(w => w.id.toLowerCase() === teller.which.toLowerCase());
+ teller.which_value = ( teller.which && which.length > 0) ?
+ which[0].value :
+ '';
+ const infoDescription = (
+
+
Address: {teller.address}
+ {(teller.which) && (
Which:: {teller.which}
)}
+ {(teller.bitshares_address) && (
BTS Account:: {teller.bitshares_address}
)}
+ {(teller.address) && (
Address:: {teller.address}
)}
+ {(teller.telegram_original) && (
)
+ }
+ {(teller.keybase) && (
Keybase: {teller.keybase}
)}
+ {(teller.whatsapp) && (
Whatsapp: {teller.whatsapp}
)}
+ {(teller.viber) && (
Viber: {teller.viber}
)}
+ {(teller.email) && (
Email: {teller.email}
)}
+ {(teller.phone) && (
Phone: {teller.phone}
)}
+ {(teller.url) && (
)}
+
+ );
const marker = {
- lat: merchant.lat,
- lng: merchant.lon,
+ lat: teller.lat,
+ lng: teller.lon,
withInfo: true,
- infoTitle: merchant.gt_name,
+ infoTitle: teller.gt_name,
infoDescription: infoDescription,
};
return marker;
@@ -530,13 +590,33 @@ class LayerMap extends Component {
handleLayerChange = name => event => {
this.setState({ [name]: event.target.checked });
// Update any time changes
- this.getAmbassadors();
- this.getMerchants();
- this.getTellers();
+ this.updateMarkers();
};
render() {
- // create an array with marker components
+ const {
+ ambassadors: ambassadorsProps,
+ merchants: merchantsProps,
+ tellers: tellersProps
+ } = this.props;
+
+ let {
+ ambassadors,
+ merchants,
+ tellers
+ } = this.state;
+
+ if(ambassadorsProps) {
+ ambassadors = ambassadorsProps;
+ }
+
+ if(merchantsProps) {
+ merchants = merchantsProps;
+ }
+
+ if(tellersProps) {
+ tellers = tellersProps;
+ }
return (
@@ -551,9 +631,9 @@ class LayerMap extends Component {
)}
}
@@ -565,4 +645,9 @@ class LayerMap extends Component {
}
}
+// Type checking the props of the component
+LayerMap.propTypes = propTypesLayerMap;
+// Assign default values to the optional props
+LayerMap.defaultProps = defaultPropsLayerMap;
+
export default LayerMap;