-
Notifications
You must be signed in to change notification settings - Fork 1
Right click menu #8
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! I can see the context menu, however there seems to be no submenu options for "Insert Command".
|
|
||
| {/* Divider */} | ||
| <div className="border-t border-falcongrey-600 my-1"></div> | ||
|
|
||
| {/* Insert Command */} | ||
| <div className="relative"> | ||
| <ContextMenuItem | ||
| onClick={() => { | ||
| setShowSubmenu(!showSubmenu) | ||
| }} | ||
| > | ||
| <div className="w-full flex justify-between gap-2"> | ||
| <span>Insert Command</span> | ||
| <svg | ||
| className={`transform transition-transform ${showSubmenu ? 'rotate-90' : ''}`} | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width="16" | ||
| height="16" | ||
| viewBox="0 0 24 24" | ||
| > | ||
| <path | ||
| fill="currentColor" | ||
| d="M8.59 16.59L13.17 12L8.59 7.41L10 6l6 6l-6 6l-1.41-1.41z" | ||
| /> | ||
| </svg> | ||
| </div> | ||
| </ContextMenuItem> | ||
|
|
||
| {/* Insert Submenu */} | ||
| {showSubmenu && ( | ||
| <div className="absolute left-full top-0 ml-1 bg-falcongrey-700 rounded-md p-1 min-w-[140px] shadow-lg"> | ||
| <ContextMenuItem | ||
| onClick={() => { | ||
| console.log("Insert Waypoint at:", clickedGpsCoords) | ||
| setClicked(false) | ||
| setShowSubmenu(false) | ||
| }} | ||
| > | ||
| <span>Waypoint</span> | ||
| </ContextMenuItem> | ||
| <ContextMenuItem | ||
| onClick={() => { | ||
| console.log("Insert Land at:", clickedGpsCoords) | ||
| setClicked(false) | ||
| setShowSubmenu(false) | ||
| }} | ||
| > | ||
| <span>Land</span> | ||
| </ContextMenuItem> | ||
| <ContextMenuItem | ||
| onClick={() => { | ||
| console.log("Insert Takeoff at:", clickedGpsCoords) | ||
| setClicked(false) | ||
| setShowSubmenu(false) | ||
| }} | ||
| > | ||
| <span>Takeoff</span> | ||
| </ContextMenuItem> | ||
| <ContextMenuItem | ||
| onClick={() => { | ||
| console.log("Insert Return to Launch at:", clickedGpsCoords) | ||
| setClicked(false) | ||
| setShowSubmenu(false) | ||
| }} | ||
| > | ||
| <span>Return to Launch</span> | ||
| </ContextMenuItem> | ||
| </div> | ||
| )} | ||
| </div> | ||
|
|
||
| {/* Delete Command */} | ||
| <ContextMenuItem | ||
| onClick={() => { | ||
| console.log("Delete command at:", clickedGpsCoords) | ||
| setClicked(false) | ||
| }} | ||
| > | ||
| <div className="w-full flex justify-between gap-2"> | ||
| <span>Delete Command</span> | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width="16" | ||
| height="16" | ||
| viewBox="0 0 24 24" | ||
| > | ||
| <path | ||
| fill="currentColor" | ||
| d="M7 21q-.825 0-1.412-.587T5 19V6H4V4h5V3h6v1h5v2h-1v13q0 .825-.587 1.413T17 21zm2-4h2V8H9zm4 0h2V8h-2z" | ||
| /> | ||
| </svg> | ||
| </div> | ||
| </ContextMenuItem> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its a little bulky... could you refactor all right click functionality (including previously written code) into its own file within gcs/src/components/missions/? You can name it missionContextMenu.jsx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work. Right now, right clicking a command prioritizes dragging/moving it instead of opening the context menu. This should be fixed so the menu opens instead, allowing the "delete command" button to work.
Within your implementation, log the number/ID of the waypoint somewhere whenever one is right clicked to confirm that the context menu correctly identifies and distinguishes between which waypoint was clicked (if any).
| useEffect(() => { | ||
| if (contextMenuRef.current && contextMenuPositionCalculationInfo) { | ||
| const contextMenuWidth = Math.round( | ||
| contextMenuRef.current.getBoundingClientRect().width, | ||
| ) | ||
| const contextMenuHeight = Math.round( | ||
| contextMenuRef.current.getBoundingClientRect().height, | ||
| ) | ||
| let x = contextMenuPositionCalculationInfo.clickedPoint.x | ||
| let y = contextMenuPositionCalculationInfo.clickedPoint.y | ||
|
|
||
| if ( | ||
| contextMenuWidth + contextMenuPositionCalculationInfo.clickedPoint.x > | ||
| contextMenuPositionCalculationInfo.canvasSize.width | ||
| ) { | ||
| x = contextMenuPositionCalculationInfo.clickedPoint.x - contextMenuWidth | ||
| } | ||
| if ( | ||
| contextMenuHeight + contextMenuPositionCalculationInfo.clickedPoint.y > | ||
| contextMenuPositionCalculationInfo.canvasSize.height | ||
| ) { | ||
| y = | ||
| contextMenuPositionCalculationInfo.clickedPoint.y - contextMenuHeight | ||
| } | ||
|
|
||
| setPoints({ x, y }) | ||
| } | ||
| }, [contextMenuPositionCalculationInfo]) | ||
|
|
||
| // Close context menu when clicking outside | ||
| useEffect(() => { | ||
| const handleClickOutside = (event) => { | ||
| if (clicked && contextMenuRef.current && !contextMenuRef.current.contains(event.target)) { | ||
| setClicked(false) | ||
| setShowSubmenu(false) | ||
| } | ||
| } | ||
|
|
||
| document.addEventListener('mousedown', handleClickOutside) | ||
| return () => { | ||
| document.removeEventListener('mousedown', handleClickOutside) | ||
| } | ||
| }, [clicked]) | ||
|
|
||
| const handleContextMenu = (e) => { | ||
| e.preventDefault() | ||
| setClicked(true) | ||
| setShowSubmenu(false) | ||
| setClickedGpsCoords(e.lngLat) | ||
| // Save coordinates for future use | ||
| setSavedCoordinates(prev => [...prev, { | ||
| lat: e.lngLat.lat, | ||
| lng: e.lngLat.lng, | ||
| timestamp: new Date().toISOString() | ||
| }]) | ||
| setContextMenuPositionCalculationInfo({ | ||
| clickedPoint: e.point, | ||
| canvasSize: { | ||
| height: e.originalEvent.target.clientHeight, | ||
| width: e.originalEvent.target.clientWidth, | ||
| }, | ||
| }) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: it seems like the menu briefly renders at its old position before updating to its newly clicked position, causing it to flash across the screen. Try and see if you can find a way to fix this, but not a critical issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Laggy menu is gone, nice job. Just waiting on right-click menu priority for waypoints instead of click-and-drag priority.
…e 2 files by goign back one commit.
…into right_click_menu
added the right click menu. i have had a bunch of issues with the tests because they cant even run due to the fact that imacs.yml is empty. also why i think i couldn't get the simulator to run with docker.