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

[FE] Hotfix/map panto 오류 수정 #611

Merged
merged 2 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions frontend/src/components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useContext, useEffect } from 'react';
import { css, styled } from 'styled-components';

import CoordinatesProvider from '../../context/CoordinatesContext';
import ImageModalContext from '../../context/ImageModalContext';
import { LayoutWidthContext } from '../../context/LayoutWidthContext';
import MarkerProvider from '../../context/MarkerContext';
import ModalProvider from '../../context/ModalContext';
Expand All @@ -16,7 +17,6 @@ import Map from '../Map';
import Toast from '../Toast';
import Logo from './Logo';
import Navbar from './Navbar';
import ImageModalContext from '../../context/ImageModalContext';

type LayoutProps = {
children: React.ReactNode;
Expand Down Expand Up @@ -70,7 +70,6 @@ function Layout({ children }: LayoutProps) {
$flexDirection="column"
height="inherit"
overflow="auto"
padding="0"
>
{children}
</Flex>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/PullPin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ const Wrapper = styled.section`
border-bottom: 4px solid ${({ theme }) => theme.color.black};

@media (max-width: 1076px) {
width: calc(50vw - 40px);
width: 50vw;
}

@media (max-width: 744px) {
width: calc(100vw - 40px);
width: 100vw;
}

@media (max-width: 372px) {
Expand Down
35 changes: 14 additions & 21 deletions frontend/src/hooks/useFocusToMarkers.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
import { useEffect, useRef } from 'react';
import { useLocation, useParams } from 'react-router-dom';
import { useEffect, useRef, useState } from 'react';

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');
const [markersLength, setMarkersLength] = useState<Number>(0);

useEffect(() => {
if (map && markers && markers.length === 1) {
map.panTo(markers[0].getPosition());
}
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
) {
if (map && markers && markers.length > 1) {
bounds.current = new Tmapv3.LatLngBounds();
markers.forEach((marker: Marker) => {
bounds.current.extend(marker.getPosition());
});

map.fitBounds(bounds.current);
if (markersLength === 0) {
setMarkersLength(markers.length);
map.fitBounds(bounds.current);
return;
}

if (markersLength !== markers.length) map.fitBounds(bounds.current);
}
return () => {
setMarkersLength(0);
};
}, [markers]);
};

export default useFocusToMarker;
Loading