import type { FC } from 'react' import { memo, useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { RiArrowGoBackLine, RiArrowGoForwardFill, } from '@remixicon/react' import TipPopup from '../operator/tip-popup' import { useWorkflowHistoryStore } from '../workflow-history-store' import { useNodesReadOnly } from '@/app/components/workflow/hooks' import ViewWorkflowHistory from '@/app/components/workflow/header/view-workflow-history' export type UndoRedoProps = { handleUndo: () => void; handleRedo: () => void } const UndoRedo: FC = ({ handleUndo, handleRedo }) => { const { t } = useTranslation() const { store } = useWorkflowHistoryStore() const [buttonsDisabled, setButtonsDisabled] = useState({ undo: true, redo: true }) useEffect(() => { const unsubscribe = store.temporal.subscribe((state) => { setButtonsDisabled({ undo: state.pastStates.length === 0, redo: state.futureStates.length === 0, }) }) return () => unsubscribe() }, [store]) const { nodesReadOnly } = useNodesReadOnly() return (
!nodesReadOnly && !buttonsDisabled.undo && handleUndo()} >
!nodesReadOnly && !buttonsDisabled.redo && handleRedo()} >
) } export default memo(UndoRedo)