Skip to content

Commit

Permalink
2065 fix current user location map view (#2152)
Browse files Browse the repository at this point in the history
* adds handleFlyTo to ResultFilter component

* fixes recenter bug

* removes unused deps

---------

Co-authored-by: Qiqi Zheng <[email protected]>
  • Loading branch information
qiqicodes and Qiqi Zheng authored Jun 4, 2024
1 parent 4b6bc48 commit 36f3c7b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,25 @@ import { tenantDetails } from "../../../../helpers/Configuration";
import CategoryButton from "./CategoryButton";
import SwitchViewsButton from "./SwitchViewsButton";
import useFeatureFlag from "hooks/useFeatureFlag";
import {
useSearchCoordinates,
useUserCoordinates,
} from "../../../../appReducer";

const ResultsFilters = ({
categoryIds,
toggleCategory,
showList,
toggleShowList,
handleFlyTo,
}) => {
const isMealsSelected = categoryIds.indexOf(MEAL_PROGRAM_CATEGORY_ID) >= 0;
const isPantrySelected = categoryIds.indexOf(FOOD_PANTRY_CATEGORY_ID) >= 0;
const { taglineText } = tenantDetails;
const { getUserLocation } = useGeolocation();
const searchCoordinates = useSearchCoordinates();
const userCoordinates = useUserCoordinates();
const startIconCoordinates = searchCoordinates || userCoordinates;
const locationPermission = useLocationPermission();
const [error, setError] = useState("");
const hasAdvancedFilterFeatureFlag = useFeatureFlag("advancedFilter");
Expand All @@ -47,7 +55,13 @@ const ResultsFilters = ({

const useMyLocationTrigger = async () => {
try {
// depending on the network speed, it might take a bit before the screen recenters to user location
await getUserLocation();
startIconCoordinates &&
handleFlyTo({
longitude: startIconCoordinates.longitude,
latitude: searchCoordinates.latitude,
});
} catch (e) {
setError(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,19 @@ const ResultsMap = (
await loadMarkerIcons(map);
setMarkersLoaded(true);
setInteractiveLayerIds([MARKERS_LAYER_ID]);
mapRef.current?.flyTo({
center: [
isListPanelOpen && !isMobile
? startIconCoordinates.longitude - 0.08
: startIconCoordinates.longitude,
isMobile
? startIconCoordinates.latitude - 0.03
: startIconCoordinates.latitude,
],
duration: 2000,
});

startIconCoordinates &&
mapRef.current?.flyTo({
center: [
isListPanelOpen && !isMobile
? startIconCoordinates.longitude - 0.08
: startIconCoordinates.longitude,
isMobile
? startIconCoordinates.latitude - 0.03
: startIconCoordinates.latitude,
],
duration: 2000,
});
}, [startIconCoordinates, isListPanelOpen, isMobile]);

const onClick = (e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const SearchResults = () => {
toggleCategory={toggleCategory}
showList={showList}
toggleShowList={toggleShowList}
handleFlyTo={flyTo}
/>
);

Expand Down

0 comments on commit 36f3c7b

Please sign in to comment.