Skip to content

Commit

Permalink
refactor: give better names to search box components that get shown/h…
Browse files Browse the repository at this point in the history
…idden
  • Loading branch information
tm-ruxandra committed Dec 16, 2024
1 parent 76a3e22 commit 72e8ebc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions dev-client/src/screens/SitesScreen/components/search/MapSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {useSitesScreenContext} from 'terraso-mobile-client/context/SitesScreenCo
import {useUpdatedForegroundPermissions} from 'terraso-mobile-client/hooks/appPermissionsHooks';
import {useIsOffline} from 'terraso-mobile-client/hooks/connectivityHooks';
import {useMapSuggestions} from 'terraso-mobile-client/hooks/useMapSuggestions';
import {MapSearchOfflineBox} from 'terraso-mobile-client/screens/SitesScreen/components/search/MapSearchOfflineBox';
import {MapSearchOfflineAlertBox} from 'terraso-mobile-client/screens/SitesScreen/components/search/MapSearchOfflineAlertBox';
import {MapSearchSuggestionBox} from 'terraso-mobile-client/screens/SitesScreen/components/search/MapSearchSuggestionBox';

type Props = {
Expand All @@ -52,7 +52,7 @@ export const MapSearch = ({zoomTo, zoomToUser, toggleMapLayer}: Props) => {
const [query, setQuery] = useState('');
const {coords, suggestions, querySuggestions, lookupFeature} =
useMapSuggestions();
const [hideResults, setHideResults] = useState(false);
const [showAutocomplete, setShowAutocomplete] = useState(false);
const sitesScreen = useSitesScreenContext();

useEffect(() => {
Expand All @@ -70,7 +70,7 @@ export const MapSearch = ({zoomTo, zoomToUser, toggleMapLayer}: Props) => {
const selectQuery = useCallback(
(name: string, mapboxId: string) => {
setQuery(name);
setHideResults(true);
setShowAutocomplete(false);
lookupFeature(mapboxId);
Keyboard.dismiss();
},
Expand All @@ -92,7 +92,7 @@ export const MapSearch = ({zoomTo, zoomToUser, toggleMapLayer}: Props) => {
<View flex={1} pointerEvents="box-none">
<Autocomplete
data={suggestions}
hideResults={hideResults || isOffline}
hideResults={!showAutocomplete || isOffline}
flatListProps={{
keyboardShouldPersistTaps: 'always',
keyExtractor: suggestion => suggestion.mapbox_id,
Expand All @@ -114,11 +114,11 @@ export const MapSearch = ({zoomTo, zoomToUser, toggleMapLayer}: Props) => {
querySuggestions(newText);
}}
onFocus={() => {
setHideResults(false);
setShowAutocomplete(true);
querySuggestions(query);
}}
onEndEditing={() => {
setHideResults(true);
setShowAutocomplete(false);
}}
value={query}
placeholder={t('search.placeholder')}
Expand All @@ -128,7 +128,11 @@ export const MapSearch = ({zoomTo, zoomToUser, toggleMapLayer}: Props) => {
}}
inputStyle={searchBarStyles.input}
/>
{isOffline && !hideResults ? <MapSearchOfflineBox /> : <></>}
{isOffline && showAutocomplete ? (
<MapSearchOfflineAlertBox />
) : (
<></>
)}
</>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {DisableableText} from 'terraso-mobile-client/components/content/typograp
import {TranslatedContent} from 'terraso-mobile-client/components/content/typography/TranslatedContent';
import {convertColorProp} from 'terraso-mobile-client/components/util/nativeBaseAdapters';

export const MapSearchOfflineBox = () => {
export const MapSearchOfflineAlertBox = () => {
return (
<View style={styles.container}>
<DisableableText disabled={true}>
Expand Down

0 comments on commit 72e8ebc

Please sign in to comment.