'use client'; import React, { useState } from 'react'; import { useReactFlow } from '@xyflow/react'; import * as Tooltip from '@radix-ui/react-tooltip'; import { Maximize, ZoomIn, ZoomOut, Undo, Redo, MessageCircle, MousePointer2, Hand, Package, Layout, Book } from 'lucide-react'; import { useFlowStoreActions } from '@/stores/flow-store'; import { useSidebarStore } from '@/stores/sidebar-store'; import useFlowStore from '@/stores/flow-store'; import { getNodeId } from '@/utils/react-flow'; import PostItIcon from '@/components/icons/PostItIcon'; interface FlowControlsProps { className?: string; } const FlowControls: React.FC = ({ className = '' }) => { const reactFlowInstance = useReactFlow(); const { undo, redo, canUndo, canRedo, addNode } = useFlowStoreActions(); const { showComments, toggleComments, floatingPanels, toggleFloatingPanel } = useSidebarStore(); const { nodes } = useFlowStore(); const [zoomLevel, setZoomLevel] = useState(100); const [activeTool, setActiveTool] = useState<'select' | 'pan'>('select'); // Count comment thread nodes const commentCount = React.useMemo(() => { return nodes.filter(node => node.type === 'commentThread').length; }, [nodes]); // Update zoom level when viewport changes React.useEffect(() => { const updateZoom = () => { const viewport = reactFlowInstance?.getViewport(); if (viewport) { setZoomLevel(Math.round(viewport.zoom * 100)); } }; // Initial zoom level updateZoom(); // Listen for viewport changes const interval = setInterval(updateZoom, 100); return () => clearInterval(interval); }, [reactFlowInstance]); // Handle tool switching - just visual for now const handleToolChange = (tool: 'select' | 'pan') => { setActiveTool(tool); }; // Handle adding a PostIt note const handleAddPostIt = () => { const viewport = reactFlowInstance?.getViewport(); const position = { x: (window.innerWidth / 2 - (viewport?.x || 0)) / (viewport?.zoom || 1) - 100, y: (window.innerHeight / 2 - (viewport?.y || 0)) / (viewport?.zoom || 1) - 100 }; const newNode = { id: getNodeId('note'), type: 'note', position, data: { text: 'Double-click to edit...', color: 'yellow' } }; addNode(newNode); }; return (
{/* Custom bottom controls */}
{/* Tool Selection */} Select Tool Pan Tool
{/* Panel Toggles */} Components Canvas EventCatalog Resources
Fit View Zoom Out
{zoomLevel}%
Current Zoom Level
Zoom In
Undo Redo
{showComments ? "Hide Comments" : "Show Comments"} {/* Sticky Note Button */} Add Sticky Note
); }; export default FlowControls;