({
messageHub,
commandManager,
onSaveScene,
onOpenScene,
onUndo,
onRedo,
onPlay,
onPause,
onStop,
onStep,
onRunInBrowser,
onRunOnDevice
}: MainToolbarProps)
| 61 | } |
| 62 | |
| 63 | export function MainToolbar({ |
| 64 | messageHub, |
| 65 | commandManager, |
| 66 | onSaveScene, |
| 67 | onOpenScene, |
| 68 | onUndo, |
| 69 | onRedo, |
| 70 | onPlay, |
| 71 | onPause, |
| 72 | onStop, |
| 73 | onStep, |
| 74 | onRunInBrowser, |
| 75 | onRunOnDevice |
| 76 | }: MainToolbarProps) { |
| 77 | const { t } = useLocale(); |
| 78 | const [playState, setPlayState] = useState<PlayState>('stopped'); |
| 79 | const [canUndo, setCanUndo] = useState(false); |
| 80 | const [canRedo, setCanRedo] = useState(false); |
| 81 | const [showRunMenu, setShowRunMenu] = useState(false); |
| 82 | const runMenuRef = useRef<HTMLDivElement>(null); |
| 83 | |
| 84 | // Close run menu when clicking outside |
| 85 | useEffect(() => { |
| 86 | if (!showRunMenu) return; |
| 87 | |
| 88 | const handleClickOutside = (e: MouseEvent) => { |
| 89 | if (runMenuRef.current && !runMenuRef.current.contains(e.target as Node)) { |
| 90 | setShowRunMenu(false); |
| 91 | } |
| 92 | }; |
| 93 | |
| 94 | const timer = setTimeout(() => { |
| 95 | document.addEventListener('click', handleClickOutside); |
| 96 | }, 10); |
| 97 | |
| 98 | return () => { |
| 99 | clearTimeout(timer); |
| 100 | document.removeEventListener('click', handleClickOutside); |
| 101 | }; |
| 102 | }, [showRunMenu]); |
| 103 | |
| 104 | useEffect(() => { |
| 105 | if (commandManager) { |
| 106 | const updateUndoRedo = () => { |
| 107 | setCanUndo(commandManager.canUndo()); |
| 108 | setCanRedo(commandManager.canRedo()); |
| 109 | }; |
| 110 | updateUndoRedo(); |
| 111 | |
| 112 | if (messageHub) { |
| 113 | const unsubscribe = messageHub.subscribe('command:executed', updateUndoRedo); |
| 114 | return () => unsubscribe(); |
| 115 | } |
| 116 | } |
| 117 | }, [commandManager, messageHub]); |
| 118 | |
| 119 | useEffect(() => { |
| 120 | if (messageHub) { |
nothing calls this directly
no test coverage detected