Skip to content

Commit

Permalink
Revert "fix: predefined places being filtered in offline mode"
Browse files Browse the repository at this point in the history
This reverts commit 785a45f.
  • Loading branch information
pac-guerreiro committed Jul 4, 2024
1 parent 4920a65 commit 0b5bbe3
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/components/AddressSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,24 @@ import CONST from '@src/CONST';
import type {Address} from '@src/types/onyx/PrivatePersonalDetails';
import CurrentLocationButton from './CurrentLocationButton';
import isCurrentTargetInsideContainer from './isCurrentTargetInsideContainer';
import type {AddressSearchProps} from './types';
import type {AddressSearchProps, PredefinedPlace} from './types';

/**
* Check if the place matches the search by the place name or description.
* @param search The search string for a place
* @param place The place to check for a match on the search
* @returns true if search is related to place, otherwise it returns false.
*/
function isPlaceMatchForSearch(search: string, place: PredefinedPlace): boolean {
if (!search) {
return true;
}
if (!place) {
return false;
}
const fullSearchSentence = `${place.name ?? ''} ${place.description}`;
return search.split(' ').every((searchTerm) => !searchTerm || fullSearchSentence.toLocaleLowerCase().includes(searchTerm.toLocaleLowerCase()));
}

// The error that's being thrown below will be ignored until we fork the
// react-native-google-places-autocomplete repo and replace the
Expand Down Expand Up @@ -305,6 +322,13 @@ function AddressSearch(
};
}, []);

const filteredPredefinedPlaces = useMemo(() => {
if (!isOffline || !searchValue) {
return predefinedPlaces ?? [];
}
return predefinedPlaces?.filter((predefinedPlace) => isPlaceMatchForSearch(searchValue, predefinedPlace)) ?? [];
}, [isOffline, predefinedPlaces, searchValue]);

const listEmptyComponent = useCallback(
() => (!isTyping ? null : <Text style={[styles.textLabel, styles.colorMuted, styles.pv4, styles.ph3, styles.overflowAuto]}>{translate('common.noResultsFound')}</Text>),
[isTyping, styles, translate],
Expand Down Expand Up @@ -348,7 +372,7 @@ function AddressSearch(
fetchDetails
suppressDefaultStyles
enablePoweredByContainer={false}
predefinedPlaces={predefinedPlaces ?? []}
predefinedPlaces={filteredPredefinedPlaces}
listEmptyComponent={listEmptyComponent}
listLoaderComponent={listLoader}
renderHeaderComponent={renderHeaderComponent}
Expand Down

0 comments on commit 0b5bbe3

Please sign in to comment.