From 6535f399f96bc198ec33fb8954716640eb8d7e87 Mon Sep 17 00:00:00 2001 From: Johannes Klein Date: Tue, 7 Oct 2025 10:56:37 +0200 Subject: [PATCH] Migrate fetchPlaceName to TS (#3122) * Rename file * Add some types * Rename file * Revert "Rename file" This reverts commit ae7d85c23f5634ed3acfa8d8ad63551ec23e6133. --- .../{fetchPlaceName.js => fetchPlaceName.ts} | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) rename src/sharedHelpers/{fetchPlaceName.js => fetchPlaceName.ts} (76%) diff --git a/src/sharedHelpers/fetchPlaceName.js b/src/sharedHelpers/fetchPlaceName.ts similarity index 76% rename from src/sharedHelpers/fetchPlaceName.js rename to src/sharedHelpers/fetchPlaceName.ts index d624a87ce..b809f6f61 100644 --- a/src/sharedHelpers/fetchPlaceName.js +++ b/src/sharedHelpers/fetchPlaceName.ts @@ -1,7 +1,5 @@ -// @flow - import NetInfo from "@react-native-community/netinfo"; -import Geocoder from "react-native-geocoder-reborn"; +import Geocoder, { GeocodingObject } from "react-native-geocoder-reborn"; // 2.5 seconds, half the time as online Suggestions // feel free to tweak this but it's here to make the camera feel speedier @@ -10,7 +8,7 @@ const GEOCODER_TIMEOUT = 2500; const TIMEOUT_ERROR_MESSAGE = "Geocoder timeout"; // lifted from SeekReactNative repo -const setPlaceName = ( results: Array ): string => { +const setPlaceName = ( results: GeocodingObject[] ): string => { let placeName = ""; const { @@ -22,7 +20,7 @@ const setPlaceName = ( results: Array ): string => { // this seems to be preferred formatting for iNat web // TODO: localize formatting // TODO: throttle requests on iOS so this doesn't error out in location picker - const appendName = name => ( placeName.length > 0 + const appendName = ( name: string ) => ( placeName.length > 0 ? `, ${name}` : name ); @@ -41,7 +39,7 @@ const setPlaceName = ( results: Array ): string => { return placeName; }; -const fetchPlaceName = async ( lat: ?number, lng: ?number ): Promise => { +const fetchPlaceName = async ( lat?: number, lng?: number ): Promise => { if ( !lat || !lng ) { return null; } const { isConnected } = await NetInfo.fetch( ); if ( !isConnected ) { return null; } @@ -56,13 +54,15 @@ const fetchPlaceName = async ( lat: ?number, lng: ?number ): Promise => timeoutPromise ] ); if ( results.length === 0 || typeof results !== "object" ) { return null; } - return setPlaceName( results ); + return setPlaceName( results as GeocodingObject[] ); } catch ( geocoderError ) { - if ( geocoderError?.message === TIMEOUT_ERROR_MESSAGE ) { + if ( ( geocoderError as Error )?.message === TIMEOUT_ERROR_MESSAGE ) { console.warn( "Geocoder operation timed out" ); return null; } - if ( !geocoderError?.message?.includes( "geocodePosition failed" ) ) throw geocoderError; + if ( !( geocoderError as Error )?.message?.includes( "geocodePosition failed" ) ) { + throw geocoderError; + } return null; } };