Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/pin detail not move #610

Merged
merged 5 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/fe-merge-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
working-directory: frontend
env:
REACT_APP_GOOGLE_ANALYTICS: ${{ secrets.REACT_APP_GOOGLE_ANALYTICS }}
REACT_APP_TMAP_API_KEY: ${{ secrets.REACT_APP_TMAP_API_KEY }}
APP_URL: "https://mapbefine.com/api"

- name: upload to artifact
Expand Down
8 changes: 4 additions & 4 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"license": "ISC",
"dependencies": {
"history": "^5.3.0",
"map-befine-swiper": "^0.8.2",
"map-befine-swiper": "^0.8.3",
"msw-storybook-addon": "^1.8.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/Map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Map() {
const { markers } = useContext(MarkerContext);
const { width } = useContext(LayoutWidthContext);
const { mapInstance, setMapInstance } = useMapStore((state) => state);

const { onFocusClickedPin } = useAnimateClickedPin();
const mapContainer = useRef(null);
const { location, requestUserLocation } = useGeoLocation(mapInstance);
const { showToast } = useToast();
Expand Down Expand Up @@ -66,7 +66,7 @@ function Map() {
useUpdateCoordinates(mapInstance);

useFocusToMarker(mapInstance, markers);
useAnimateClickedPin(mapInstance, markers);
onFocusClickedPin(mapInstance, markers);

return (
<MapContainer>
Expand Down Expand Up @@ -116,4 +116,4 @@ const CurrentLocationIcon = styled(CurrentLocation)`
}
`;

export default Map;
export default Map;
44 changes: 34 additions & 10 deletions frontend/src/hooks/useAnimateClickedPin.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
import { useEffect } from 'react';
import { useEffect, useState } from 'react';

const useAnimateClickedPin = (map: TMap | null, markers: Marker[]) => {
const useAnimateClickedPin = () => {
const queryParams = new URLSearchParams(location.search);
const [checkQueryParams, setCheckQueryParams] = useState<any>(queryParams);

useEffect(() => {
if (queryParams.has('pinDetail')) {
const pinId = queryParams.get('pinDetail');
const marker = markers.find((marker: Marker) => marker.id === pinId);
const onFocusClickedPin = (map: TMap | null, markers: Marker[]) => {
useEffect(() => {
const currentQueryParams = new URLSearchParams(location.search);

if (checkQueryParams === null) {
if (!map) return;
const pinId = queryParams.get('pinDetail');
const marker = markers.find((marker: Marker) => marker.id === pinId);

if (!marker) return;

if (marker && map) {
map.setCenter(marker.getPosition());
map.setZoom(17);

setCheckQueryParams(currentQueryParams);
return;
}
}
}, [markers, map, queryParams]);

if (
checkQueryParams.get('pinDetail') !==
currentQueryParams.get('pinDetail')
) {
const pinId = queryParams.get('pinDetail');
const marker = markers.find((marker: Marker) => marker.id === pinId);

if (marker && map) {
map.setCenter(marker.getPosition());
map.setZoom(17);
}
setCheckQueryParams(currentQueryParams);
}
}, [markers, map, queryParams]);
};

return { checkQueryParams, onFocusClickedPin };
};

export default useAnimateClickedPin;
21 changes: 18 additions & 3 deletions frontend/src/hooks/useFocusToMarkers.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
import { useEffect, useRef } from 'react';
import { useLocation, useParams } from 'react-router-dom';

const useFocusToMarker = (map: TMap | null, markers: Marker[]) => {
const { Tmapv3 } = window;
const bounds = useRef(new Tmapv3.LatLngBounds());

const params = useLocation();
const queryParams = new URLSearchParams(window.location.search);
const pinDetail = queryParams.get('pinDetail');
useEffect(() => {
if (map && markers && markers.length === 1) {
map.panTo(markers[0].getPosition());
}

if (map && markers && markers.length > 1) {
if (map && pinDetail) {
const marker = markers.find((marker: Marker) => marker.id === pinDetail);
if (marker) {
map.setCenter(marker.getPosition());
map.setZoom(17);
}
}
if (
map &&
markers &&
markers.length > 1 &&
params.pathname.includes('see-together') &&
!pinDetail
) {
bounds.current = new Tmapv3.LatLngBounds();
markers.forEach((marker: Marker) => {
bounds.current.extend(marker.getPosition());
Expand Down
Loading