= props => {
const scaleFactorY = 180 / canvasSize.height;
const finalScale = Math.min(scaleFactorX, scaleFactorY);
+ const {
+ showContextMenu,
+ contextMenuRef,
+ setShowContextMenu,
+ handleShowContextMenu,
+ } = useContextMenu();
+
return (
- onSetActivePage(page.id)}
- >
-
-
- {shapes.map(shape => {
- if (!fakeShapeRefs.current[shape.id]) {
- fakeShapeRefs.current[shape.id] = createRef();
- }
- return renderShapeComponent(shape, {
- handleSelected: () => {},
- shapeRefs: fakeShapeRefs,
- handleDragEnd:
- (_: string) => (_: KonvaEventObject) => {},
- handleTransform: () => {},
- });
- })}
-
-
-
+ <>
+ onSetActivePage(page.id)}
+ onContextMenu={handleShowContextMenu}
+ >
+
+
+ {shapes.map(shape => {
+ if (!fakeShapeRefs.current[shape.id]) {
+ fakeShapeRefs.current[shape.id] = createRef();
+ }
+ return renderShapeComponent(shape, {
+ handleSelected: () => {},
+ shapeRefs: fakeShapeRefs,
+ handleDragEnd:
+ (_: string) => (_: KonvaEventObject) => {},
+ handleTransform: () => {},
+ });
+ })}
+
+
+ {showContextMenu && (
+
+ )}
+
+ >
);
};
diff --git a/src/pods/thumb-pages/use-context-menu-thumb.hook.tsx b/src/pods/thumb-pages/use-context-menu-thumb.hook.tsx
new file mode 100644
index 00000000..5d5a65a6
--- /dev/null
+++ b/src/pods/thumb-pages/use-context-menu-thumb.hook.tsx
@@ -0,0 +1,42 @@
+import { useCanvasContext } from '@/core/providers';
+import { useEffect, useRef, useState } from 'react';
+
+export const useContextMenu = () => {
+ const [showContextMenu, setShowContextMenu] = useState(false);
+ const contextMenuRef = useRef(null);
+ const { setIsThumbnailContextMenuVisible } = useCanvasContext();
+
+ const handleShowContextMenu = (
+ event: React.MouseEvent
+ ) => {
+ event.preventDefault();
+ if (!showContextMenu) {
+ setIsThumbnailContextMenuVisible(true);
+ setShowContextMenu(true);
+ }
+ };
+
+ useEffect(() => {
+ const closeContextMenu = (event: MouseEvent) => {
+ if (
+ contextMenuRef.current &&
+ !contextMenuRef.current.contains(event.target as Node)
+ ) {
+ setShowContextMenu(false);
+ setIsThumbnailContextMenuVisible(false);
+ }
+ };
+
+ window.addEventListener('mousedown', closeContextMenu);
+ return () => {
+ window.removeEventListener('mousedown', closeContextMenu);
+ };
+ }, [showContextMenu, setIsThumbnailContextMenuVisible]);
+
+ return {
+ showContextMenu,
+ contextMenuRef,
+ setShowContextMenu,
+ handleShowContextMenu,
+ };
+};