Skip to content

Commit

Permalink
fix: problem with mapview not loading
Browse files Browse the repository at this point in the history
  • Loading branch information
hopetambala committed Oct 26, 2020
1 parent 6e14668 commit 91e49d8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 36 deletions.
6 changes: 4 additions & 2 deletions components/FindResidents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ const FindResidents = ({

const fetchData = async () => {
await getData('residentData').then((residentData) => {
setData(residentData || []);
setResidents(residentData.slice() || [].slice());
if (residentData) {
setData(residentData || []);
setResidents(residentData.slice() || [].slice());
}
});

const queryParams = {
Expand Down
68 changes: 37 additions & 31 deletions components/MapView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,36 @@ import getLocation from '../../modules/geolocation';
import { theme } from '../../modules/theme';
import { getData } from '../../modules/async-storage';

import { residentIDQuery } from '../../services/parse/crud';
// import { residentIDQuery } from '../../services/parse/crud';

const Maps = ({ organization }) => {
const Maps = () => {
const [region, setRegion] = useState({
latitude: 18.4861,
longitude: -69.9312,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
});

const [markers, setMarkers] = useState([]);

useEffect(() => {
getData('residentData').then((residentData) => {
setMarkers(residentData);
});

let isSubscribed = true;

retrieveMarkers().then((records) => {
if (isSubscribed) {
if (records.length === 0) {
setMarkers(records); // sets records if promise is reached during mounting
}
}
});
return function cleanup() {
isSubscribed = false; // cancels promise when component unmounts
};
retriveAsyncMarkers();
}, []);

// useEffect(() => {
// let isSubscribed = true;
// retrieveMarkers().then((records) => {
// if (isSubscribed) {
// if (records !== markers) {
// setMarkers(records); // sets records if promise is reached during mounting
// }
// }
// });
// return function cleanup() {
// isSubscribed = false; // cancels promise when component unmounts
// };
// }, []);

const handleLocation = async () => {
const currentLocation = await getLocation();
const { latitude, longitude } = currentLocation.coords;
Expand All @@ -48,25 +48,33 @@ const Maps = ({ organization }) => {
});
};

const retrieveMarkers = async () => {
const queryParams = {
skip: 0,
offset: 0,
limit: 10000,
parseColumn: 'surveyingOrganization',
parseParam: organization,
};

return residentIDQuery(queryParams).then((recs) => JSON.parse(JSON.stringify(recs)));
const retriveAsyncMarkers = async () => {
getData('residentData').then((residentData) => {
if (residentData) {
setMarkers(residentData);
}
});
};

// const retrieveMarkers = async () => {
// const queryParams = {
// skip: 0,
// offset: 0,
// limit: 10000,
// parseColumn: 'surveyingOrganization',
// parseParam: organization,
// };

// return residentIDQuery(queryParams).then((recs) => JSON.parse(JSON.stringify(recs)));
// };

return (
<View style={styles.container}>
<MapView
style={styles.mapStyle}
region={region}
>
{markers.length > 1 && markers.map((marker) => (
{markers && markers.map((marker) => (
marker.location && (
<Marker
key={marker.objectId}
Expand All @@ -83,8 +91,6 @@ const Maps = ({ organization }) => {
onPress={handleLocation}
color={theme.colors.primary}
style={{ backgroundColor: theme.colors.background, opacity: 0.8 }}

// animated
/>
</View>
</View>
Expand Down
2 changes: 1 addition & 1 deletion domains/Auth/SignIn/ForgotPassword/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function ForgotPassword({ navigation, setForgotPassword }) {
{(formikProps) => (
<View>
<View>
<Text style={{ marginHorizontal: 15, fontSize: 20, fontWeight: 'bold' }}>{I18n.t('signIn.forgotPassword.enterEmail')}</Text>
<Text style={{ marginHorizontal: 15, fontSize: 20, fontWeight: 'bold' }}>{I18n.t('signIn.forgotPassword.enterEmail')}</Text>
<FormInput
label="Email"
formikProps={formikProps}
Expand Down
6 changes: 4 additions & 2 deletions modules/cached-resources/useCachedResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ export default function useCachedResources() {
SplashScreen.preventAutoHideAsync();

await getData('organization').then(async (org) => {
const residentData = await fetchResidentData(org);
storeData(residentData, 'residentData');
if (org) {
const residentData = await fetchResidentData(org);
storeData(residentData, 'residentData');
}
});
} catch (e) {
// We might want to provide this error information to an error reporting service
Expand Down

0 comments on commit 91e49d8

Please sign in to comment.