Skip to content

Commit

Permalink
✨ MainPage 클릭이벤트 막는 방식 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
KimGaeun0806 committed Feb 29, 2024
1 parent a0fa236 commit db4cf67
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
16 changes: 15 additions & 1 deletion src/pages/main/MainPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';

import AddIcon from '@/assets/icons/add.svg?react';
import AsyncBoundary from '@/components/async-boundary';
Expand Down Expand Up @@ -28,6 +28,20 @@ const MainPage = () => {
openModal(<MakeNewCourseModal />);
};

useEffect(() => {
const handleMapContainerClick = (event: MouseEvent) => {
event.stopPropagation();
};

const mapContainer = mapContainerRef.current;

mapContainer?.addEventListener('click', handleMapContainerClick, true);

return () => {
mapContainer?.removeEventListener('click', handleMapContainerClick);
};
}, [mapContainerRef]);

return (
<>
<GlobalNavigationBar />
Expand Down
28 changes: 11 additions & 17 deletions src/utils/tmap/tmapModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ export interface TmapConstructorType {

const { Tmapv3 } = window;

const pathname = window.location.pathname;
const isCoursePage = pathname.split('/')[1] === 'course';

export class TMapModule {
#mapInstance: typeof Tmapv3.Map;
#markers: MarkerType[] = [];
Expand Down Expand Up @@ -93,22 +90,19 @@ export class TMapModule {
});
};

if (isCoursePage)
(() => {
this.#mapInstance.on('Click', handleMapClick);
this.#mapInstance.on('Click', handleMapClick);

let throttleTimeout: NodeJS.Timeout | null = null;
const THROTTLE_TIME = 800;
let throttleTimeout: NodeJS.Timeout | null = null;
const THROTTLE_TIME = 800;

this.#mapInstance.on('Zoom', () => {
if (!throttleTimeout) {
throttleTimeout = setTimeout(() => {
this.clusterMarkers();
throttleTimeout = null;
}, THROTTLE_TIME);
}
});
})();
this.#mapInstance.on('Zoom', () => {
if (!throttleTimeout) {
throttleTimeout = setTimeout(() => {
this.clusterMarkers();
throttleTimeout = null;
}, THROTTLE_TIME);
}
});
}

// 마커 생성
Expand Down

0 comments on commit db4cf67

Please sign in to comment.