diff --git a/src/components/organisms/BrowserWindow.tsx b/src/components/organisms/BrowserWindow.tsx index d81ff967..f0d21902 100644 --- a/src/components/organisms/BrowserWindow.tsx +++ b/src/components/organisms/BrowserWindow.tsx @@ -3,12 +3,42 @@ import { useSocketStore } from '../../context/socket'; import Canvas from "../atoms/canvas"; import { useBrowserDimensionsStore } from "../../context/browserDimensions"; import { Highlighter } from "../atoms/Highlighter"; +import { GenericModal } from '../atoms/GenericModal'; +import { Button, Typography, Box } from '@mui/material'; + +interface ConfirmationBoxProps { + selector: string; + onYes: () => void; + onNo: () => void; +} + +// New component for the confirmation box inside the modal +const ConfirmationBox = ({ selector, onYes, onNo }: ConfirmationBoxProps) => { + return ( + + + Confirmation + + + Do you want to interact with the element: {selector}? + + + + + + + ); +}; export const BrowserWindow = () => { - const [canvasRef, setCanvasReference] = useState | undefined>(undefined); const [screenShot, setScreenShot] = useState(""); const [highlighterData, setHighlighterData] = useState<{ rect: DOMRect, selector: string } | null>(null); + const [showConfirmation, setShowConfirmation] = useState(false); const { socket } = useSocketStore(); const { width, height } = useBrowserDimensionsStore(); @@ -46,10 +76,8 @@ export const BrowserWindow = () => { return () => { socket?.off("screencast", screencastHandler); } - }, [screenShot, canvasRef, socket, screencastHandler]); - const highlighterHandler = useCallback((data: { rect: DOMRect, selector: string }) => { setHighlighterData(data); console.log('Highlighter Rect via socket:', data.rect) @@ -60,15 +88,53 @@ export const BrowserWindow = () => { if (socket) { socket.on("highlighter", highlighterHandler); } - //cleaning function return () => { document.removeEventListener('mousemove', onMouseMove); socket?.off("highlighter", highlighterHandler); }; }, [socket, onMouseMove]); + const handleClick = (e: React.MouseEvent) => { + if (highlighterData && canvasRef?.current) { + const canvasRect = canvasRef.current.getBoundingClientRect(); + const clickX = e.clientX - canvasRect.left; + const clickY = e.clientY - canvasRect.top; + + const highlightRect = highlighterData.rect; + if ( + clickX >= highlightRect.left && + clickX <= highlightRect.right && + clickY >= highlightRect.top && + clickY <= highlightRect.bottom + ) { + setShowConfirmation(true); + } + } + }; + + const handleConfirmation = (confirmed: boolean) => { + if (confirmed) { + console.log(`User confirmed interaction with: ${highlighterData?.selector}`); + // Here you can add logic to interact with the element + } else { + console.log('User declined interaction'); + } + setShowConfirmation(false); + }; + return ( - <> +
+ setShowConfirmation(false)} + canBeClosed={false} + > + handleConfirmation(true)} + onNo={() => handleConfirmation(false)} + /> + {(highlighterData?.rect != null && highlighterData?.rect.top != null) && canvasRef?.current ? { width={width} height={height} /> - +
); };