Skip to content

Commit

Permalink
Change GeolocationErrorCode type
Browse files Browse the repository at this point in the history
  • Loading branch information
filip-solecki committed Jan 15, 2024
1 parent b83915e commit c5f84b6
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1967,8 +1967,8 @@ SPEC CHECKSUMS:
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
Turf: 13d1a92d969ca0311bbc26e8356cca178ce95da2
VisionCamera: 7d13aae043ffb38b224a0f725d1e23ca9c190fe7
Yoga: e64aa65de36c0832d04e8c7bd614396c77a80047
Yoga: 13c8ef87792450193e117976337b8527b49e8c03

PODFILE CHECKSUM: 0ccbb4f2406893c6e9f266dc1e7470dcd72885d2

COCOAPODS: 1.13.0
COCOAPODS: 1.14.3
6 changes: 3 additions & 3 deletions src/components/AddressSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {GooglePlacesAutocomplete} from 'react-native-google-places-autocomplete'
import type {GooglePlaceData, GooglePlaceDetail} from 'react-native-google-places-autocomplete';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import LocationErrorMessage from '@components/LocationErrorMessage';
import type {LocationErrorCodeType} from '@components/LocationErrorMessage/types';
import TextInput from '@components/TextInput';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
Expand All @@ -15,6 +14,7 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ApiUtils from '@libs/ApiUtils';
import getCurrentPosition from '@libs/getCurrentPosition';
import type {GeolocationErrorCodeType} from '@libs/getCurrentPosition/getCurrentPosition.types';
import * as GooglePlacesUtils from '@libs/GooglePlacesUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -69,7 +69,7 @@ function AddressSearch(
const [isFocused, setIsFocused] = useState(false);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [searchValue, setSearchValue] = useState(value || defaultValue || '');
const [locationErrorCode, setLocationErrorCode] = useState<LocationErrorCodeType>(null);
const [locationErrorCode, setLocationErrorCode] = useState<GeolocationErrorCodeType | null>(null);
const [isFetchingCurrentLocation, setIsFetchingCurrentLocation] = useState(false);
const shouldTriggerGeolocationCallbacks = useRef(true);
const containerRef = useRef<View>(null);
Expand Down Expand Up @@ -260,7 +260,7 @@ function AddressSearch(
}

setIsFetchingCurrentLocation(false);
setLocationErrorCode(errorData.code as LocationErrorCodeType);
setLocationErrorCode(errorData.code);
},
{
maximumAge: 0, // No cache, always get fresh location info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import colors from '@styles/theme/colors';
import CONST from '@src/CONST';
import type {LocationErrorMessageProps} from './types';
import type LocationErrorMessageProps from './types';

type BaseLocationErrorMessageProps = LocationErrorMessageProps & {
/** A callback that runs when 'allow location permission' link is pressed */
Expand Down
2 changes: 1 addition & 1 deletion src/components/LocationErrorMessage/index.native.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import {Linking} from 'react-native';
import BaseLocationErrorMessage from './BaseLocationErrorMessage';
import type {LocationErrorMessageProps} from './types';
import type LocationErrorMessageProps from './types';

/** Opens app level settings from the native system settings */
const openAppSettings = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/LocationErrorMessage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import {Linking} from 'react-native';
import CONST from '@src/CONST';
import BaseLocationErrorMessage from './BaseLocationErrorMessage';
import type {LocationErrorMessageProps} from './types';
import type LocationErrorMessageProps from './types';

/** Opens expensify help site in a new browser tab */
const navigateToExpensifyHelpSite = () => {
Expand Down
6 changes: 3 additions & 3 deletions src/components/LocationErrorMessage/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type LocationErrorCodeType = -1 | 1 | 2 | 3 | null;
import type {GeolocationErrorCodeType} from '@libs/getCurrentPosition/getCurrentPosition.types';

type LocationErrorMessageProps = {
/** A callback that runs when close icon is pressed */
Expand All @@ -11,7 +11,7 @@ type LocationErrorMessageProps = {
* - code 2 = location is unavailable or there is some connection issue
* - code 3 = location fetch timeout
*/
locationErrorCode?: LocationErrorCodeType;
locationErrorCode?: GeolocationErrorCodeType | null;
};

export type {LocationErrorMessageProps, LocationErrorCodeType};
export default LocationErrorMessageProps;
8 changes: 6 additions & 2 deletions src/libs/getCurrentPosition/getCurrentPosition.types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type {ValueOf} from 'type-fest';

type GeolocationSuccessCallback = (position: {
coords: {
latitude: number;
Expand All @@ -11,8 +13,10 @@ type GeolocationSuccessCallback = (position: {
timestamp: number;
}) => void;

type GeolocationErrorCodeType = ValueOf<typeof GeolocationErrorCode>;

type GeolocationErrorCallback = (error: {
code: (typeof GeolocationErrorCode)[keyof typeof GeolocationErrorCode];
code: GeolocationErrorCodeType;
message: string;
PERMISSION_DENIED: typeof GeolocationErrorCode.PERMISSION_DENIED;
POSITION_UNAVAILABLE: typeof GeolocationErrorCode.POSITION_UNAVAILABLE;
Expand Down Expand Up @@ -51,4 +55,4 @@ type GetCurrentPosition = (success: GeolocationSuccessCallback, error: Geolocati

export {GeolocationErrorCode};

export type {GeolocationSuccessCallback, GeolocationErrorCallback, GeolocationOptions, GetCurrentPosition};
export type {GeolocationSuccessCallback, GeolocationErrorCallback, GeolocationOptions, GetCurrentPosition, GeolocationErrorCodeType};

0 comments on commit c5f84b6

Please sign in to comment.