Skip to content

Commit

Permalink
Merge pull request #610 from woowacourse-teams/hotfix/pinDetail-not-move
Browse files Browse the repository at this point in the history
Hotfix/pin detail not move
  • Loading branch information
jiwonh423 authored Oct 19, 2023
2 parents fa683fd + 50a5eac commit a8f64a4
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 22 deletions.
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
2 changes: 1 addition & 1 deletion frontend/src/components/Banner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import useNavigator from '../../hooks/useNavigator';
import Box from '../common/Box';

const USAGE_URL =
'https://yoondgu.notion.site/3e5b3c98c4814aa1bd5887104fee314e?pvs=4';
'https://sites.google.com/woowahan.com/woowacourse-demo-5th/%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8/%EA%B4%9C%EC%B0%AE%EC%9D%84%EC%A7%80%EB%8F%84';

export default function Banner() {
const { routePage } = useNavigator();
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

0 comments on commit a8f64a4

Please sign in to comment.