Skip to content
Snippets Groups Projects
Commit c3fae5a6 authored by utkarsh_33's avatar utkarsh_33
Browse files

Fixed the flickering problem

parent 3b3096a1
No related branches found
No related tags found
1 merge request!96#3459249: Handled context menu on right click
Pipeline #273062 passed with warnings
......@@ -29,6 +29,7 @@ const RightClickMenu: React.FC<RightClickMenuProps> = (props) => {
x: number;
y: number;
}>({ x: 0, y: 0 });
const [isPositionUpdated, setIsPositionUpdated] = useState(false);
const contextMenuOpenRef = useRef(contextMenuOpen);
const dispatch = useAppDispatch();
......@@ -36,30 +37,31 @@ const RightClickMenu: React.FC<RightClickMenuProps> = (props) => {
contextMenuOpenRef.current = contextMenuOpen;
}, [contextMenuOpen]);
useEffect(() => {
if (!iframeRef.current) {
return;
}
const updateContextMenuPosition = useCallback(() => {
if (iframeRef.current) {
const iframeRect = iframeRef.current.getBoundingClientRect();
if (mouseEventPosition !== null) {
setContextMenuPosition({
x: iframeRect.x + mouseEventPosition?.pageX,
y: iframeRect.y + mouseEventPosition?.pageY,
});
} else {
setContextMenuPosition({
x: iframeRect.x,
y: iframeRect.y,
x: iframeRect.x + mouseEventPosition.pageX,
y: iframeRect.y + mouseEventPosition.pageY,
});
setIsPositionUpdated(true);
}
}, [iframeRef, mouseEventPosition]);
useEffect(() => {
if (contextMenuOpen === viewportSize) {
setIsPositionUpdated(false);
updateContextMenuPosition();
}
}, [contextMenuOpen, updateContextMenuPosition, viewportSize]);
const handleLeftClick = useCallback(
(event: MouseEvent) => {
if (contextMenuOpenRef.current) {
event.preventDefault();
dispatch(setIsContextMenuOpen(undefined));
dispatch(unsetHoveredComponent());
setIsPositionUpdated(false);
}
},
[dispatch],
......@@ -112,7 +114,7 @@ const RightClickMenu: React.FC<RightClickMenuProps> = (props) => {
dispatch(shiftNode({ uuid: elementId, direction: 'down' }));
}
if (contextMenuOpen === viewportSize) {
if (contextMenuOpen === viewportSize && isPositionUpdated) {
return (
<>
<DropdownMenu.Root open={!!contextMenuOpen}>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment