diff --git a/cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/handle-popover-visibility.tsx b/cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/handle-popover-visibility.tsx index 32abeda93771..2ef920fff0a8 100644 --- a/cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/handle-popover-visibility.tsx +++ b/cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/handle-popover-visibility.tsx @@ -2,48 +2,13 @@ // // SPDX-License-Identifier: MIT -import React, { useEffect, useState } from 'react'; +import React, { useState } from 'react'; import Popover, { PopoverProps } from 'antd/lib/popover'; -type PopoverTypeListener = (activePopover: string | null) => void; - -let listeners: PopoverTypeListener[] = []; -function updateActivePopoverType(activePopover: string | null): void { - for (const listener of listeners) { - listener(activePopover); - } -} - -function subscribePopoverUpdate(onUpdate: PopoverTypeListener): void { - listeners.push(onUpdate); -} - -function unsubscribePopoverUpdate(onUpdate: PopoverTypeListener): void { - listeners = listeners.filter((listener: PopoverTypeListener) => listener !== onUpdate); -} - -function useCurrentActivePopover(): string | null { - const [activePopover, setActivePopover] = useState(null); - - useEffect(() => { - const listener: PopoverTypeListener = (newActivePopover: string | null) => { - // updating the state leads to rerender of dependent components - setActivePopover(newActivePopover); - }; - - // subscribe on mount and unsubscribe on unmount - subscribePopoverUpdate(listener); - return () => unsubscribePopoverUpdate(listener); - }, []); - - return activePopover; -} - export default function withVisibilityHandling(WrappedComponent: typeof Popover, popoverType: string) { return (props: PopoverProps): JSX.Element => { const [initialized, setInitialized] = useState(false); const [visible, setVisible] = useState(false); - const currentActivePopover = useCurrentActivePopover(); const { overlayClassName, ...rest } = props; const overlayClassNames = typeof overlayClassName === 'string' ? overlayClassName.split(/\s+/) : []; @@ -56,7 +21,6 @@ export default function withVisibilityHandling(WrappedComponent: typeof Popover, const callback = (event: Event): void => { if ((event as AnimationEvent).animationName === 'antZoomBigIn') { - updateActivePopoverType(popoverType); setVisible(true); } }; @@ -64,7 +28,7 @@ export default function withVisibilityHandling(WrappedComponent: typeof Popover, return ( { if (!_visible) {