diff --git a/src/sharedHooks/useWatchPosition.ts b/src/sharedHooks/useWatchPosition.ts index 9f0da6373..af08d4d66 100644 --- a/src/sharedHooks/useWatchPosition.ts +++ b/src/sharedHooks/useWatchPosition.ts @@ -2,6 +2,7 @@ import Geolocation, { GeolocationError, GeolocationResponse } from "@react-native-community/geolocation"; +import _ from "lodash"; import { useEffect, useState } from "react"; import { RESULTS as PERMISSION_RESULTS @@ -68,21 +69,28 @@ const useWatchPosition = ( options: { positional_accuracy: accuracy }; if ( !currentPosition || !accuracy ) { return; } - updateObservationKeys( newLocation ); + // right now, we're returning a userLocation for the Projects and Camera + // screens, and we're updating observation keys in ObsEdit so the location + // is added directly to the observation. once changes to permissions flow are + // done, we'll want to also update observation keys via Suggestions (instead of + // adding location in the Camera) + if ( !_.isEmpty( currentObservation ) ) { + updateObservationKeys( newLocation ); + } setUserLocation( newLocation ); if ( accuracy < TARGET_POSITIONAL_ACCURACY ) { Geolocation.clearWatch( subscriptionId ); setSubscriptionId( null ); setCurrentPosition( null ); } - }, [currentPosition, subscriptionId, updateObservationKeys] ); + }, [currentPosition, subscriptionId, updateObservationKeys, currentObservation] ); useEffect( ( ) => { const beginLocationFetch = async ( ) => { const permissionResult = await checkLocationPermission( ); setLocationPermissionResult( permissionResult ); const startFetchLocation = await shouldFetchObservationLocation( currentObservation ); - if ( startFetchLocation ) { + if ( _.isEmpty( currentObservation ) || startFetchLocation ) { watchPosition( ); } else { setShouldFetchLocation( false );