Skip to content

Commit

Permalink
fix: subscription to map
Browse files Browse the repository at this point in the history
  • Loading branch information
hopetambala committed Oct 18, 2020
1 parent d3831c7 commit 71ee915
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions components/MapView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IconButton } from 'react-native-paper';

import getLocation from '../../modules/geolocation';
import { theme } from '../../modules/theme';
import { getObjectsByGeolocation, residentIDQuery } from '../../services/parse/crud';
import { residentIDQuery } from '../../services/parse/crud';

const Maps = ({ organization }) => {
const [region, setRegion] = useState({
Expand All @@ -18,39 +18,35 @@ const Maps = ({ organization }) => {
const [markers, setMarkers] = useState([]);

useEffect(() => {
retrieveMarkers()
}, [])
retrieveMarkers();
return function cleanup() {
// we need to cleanup something here
};
}, []);

const handleLocation = async () => {
const currentLocation = await getLocation();
const { latitude, longitude } = currentLocation.coords;
setRegion({
...region,
latitude: latitude,
longitude: longitude,
latitude,
longitude,
});
};

const retrieveMarkers = async () => {
// const queryParams = {
// limit: 10000,
// parseColumn: 'surveyingOrganization',
// parseParam: organization,
// lat: region.latitude,
// long: region.longitude,
// };
// let records = await getObjectsByGeolocation(queryParams);
// records = JSON.parse(JSON.stringify(records));
const queryParams = {
skip: 0,
offset: 0,
limit: 10000,
parseColumn: 'surveyingOrganization',
parseParam: organization,
};
let records = await residentIDQuery(queryParams);
records = JSON.parse(JSON.stringify(records));
setMarkers(records);

await residentIDQuery(queryParams).then((records) => {
const residentRecords = JSON.parse(JSON.stringify(records));
setMarkers(residentRecords);
});
};

return (
Expand All @@ -59,14 +55,15 @@ const Maps = ({ organization }) => {
style={styles.mapStyle}
region={region}
>
{markers.length > 1 && markers.map((marker, index) => (
{markers.map((marker) => (
marker.location && (
<Marker
key={marker.objectId}
coordinate={marker.location}
title={`${marker.fname || ""} ${marker.lname || ""}`}
// description={marker.description}
/>)
title={`${marker.fname || ''} ${marker.lname || ''}`}
description={`Collector: ${marker.surveyingUser}`}
/>
)
))}
</MapView>
<View style={styles.buttonStyle}>
Expand Down

0 comments on commit 71ee915

Please sign in to comment.