import type { FC } from 'react' import { RiArrowGoBackLine, RiArrowGoForwardFill, } from '@remixicon/react' import { memo, useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { collaborationManager } from '@/app/components/workflow/collaboration/core/collaboration-manager' import ViewWorkflowHistory from '@/app/components/workflow/header/view-workflow-history' import { useNodesReadOnly } from '@/app/components/workflow/hooks' import { cn } from '@/utils/classnames' import Divider from '../../base/divider' import TipPopup from '../operator/tip-popup' export type UndoRedoProps = { handleUndo: () => void, handleRedo: () => void } const UndoRedo: FC = ({ handleUndo, handleRedo }) => { const { t } = useTranslation() const [buttonsDisabled, setButtonsDisabled] = useState({ undo: true, redo: true }) useEffect(() => { // Update button states based on Loro's UndoManager const updateButtonStates = () => { setButtonsDisabled({ undo: !collaborationManager.canUndo(), redo: !collaborationManager.canRedo(), }) } // Initial state Promise.resolve().then(() => { updateButtonStates() }) // Listen for undo/redo state changes const unsubscribe = collaborationManager.onUndoRedoStateChange((state) => { setButtonsDisabled({ undo: !state.canUndo, redo: !state.canRedo, }) }) return () => unsubscribe() }, []) const { nodesReadOnly } = useNodesReadOnly() return (
!nodesReadOnly && !buttonsDisabled.undo && handleUndo()} >
!nodesReadOnly && !buttonsDisabled.redo && handleRedo()} >
) } export default memo(UndoRedo)