Skip to content

Commit

Permalink
fixed popup flicker
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukthiw committed Aug 2, 2024
1 parent bbbdbe6 commit 7171f6e
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions Eplant/views/WorldEFP/MapContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ const MapContainer = ({ activeData, state }: MapContainerProps) => {
const [hoveredMarkerId, setHoveredMarkerId] = useState<string>('')
const [isCollapse] = useSidebarState()

const handleMouseOver = (event: MouseEvent<HTMLDivElement>, id: string) => {
setInfoWindowShown(true)
const mouseX = isCollapse ? event.clientX : event.clientX - sidebarWidth
const mouseY = event.clientY
setMousePosition({
x: mouseX,
y: mouseY,
})
setHoveredMarkerId(id)
const handleMouseEnter = (event: MouseEvent<HTMLDivElement>, id: string) => {
if (!infoWindowShown) {
setInfoWindowShown(true)
const mouseX = isCollapse ? event.clientX : event.clientX - sidebarWidth
const mouseY = event.clientY
setMousePosition({
x: mouseX,
y: mouseY,
})
setHoveredMarkerId(id)
}
}

const handleMouseOut = (event: MouseEvent<HTMLDivElement>) => {
const handleMouseLeave = (event: MouseEvent<HTMLDivElement>) => {
setInfoWindowShown(false)
setMousePosition({
x: 0,
Expand All @@ -60,17 +62,18 @@ const MapContainer = ({ activeData, state }: MapContainerProps) => {
<>
<AdvancedMarker key={index} position={pos}>
<div
onMouseOver={(event) => handleMouseOver(event, markerId)}
onMouseLeave={handleMouseOut}
onMouseOver={(event) => handleMouseEnter(event, markerId)}
onMouseLeave={handleMouseLeave}
style={{
width: 24,
height: 24,
position: 'absolute',
opacity: 0,
backgroundColor: 'white',
opacity: 1,
backgroundColor: 'rgba(52, 52, 52, 0)',
}}
></div>
<WorldEFPIcon sx={{ fill: colour }}></WorldEFPIcon>
>
<WorldEFPIcon sx={{ fill: colour }}></WorldEFPIcon>
</div>
</AdvancedMarker>
{infoWindowShown && markerId === hoveredMarkerId && (
<InfoContent
Expand Down

0 comments on commit 7171f6e

Please sign in to comment.