Add historyCurrentStep to setHistory event

This commit is contained in:
Eric NGUYEN 2022-10-13 16:18:16 +02:00
parent 749609f9a0
commit 7a81bbaec6
3 changed files with 14 additions and 10 deletions

View file

@ -158,7 +158,7 @@ function UseCustomEvents(
historyCurrentStep: number,
configuration: IConfiguration,
editorRef: React.RefObject<HTMLDivElement>,
setNewHistory: (newHistory: IHistoryState[]) => void
setNewHistory: (newHistory: IHistoryState[], historyCurrentStep?: number) => void
): void {
useEffect(() => {
const editorState: IEditorState = {
@ -219,10 +219,10 @@ function UseEditorListener(
function UseNewHistoryState(
setHistory: Dispatch<SetStateAction<IHistoryState[]>>,
setHistoryCurrentStep: Dispatch<SetStateAction<number>>
): (newHistory: IHistoryState[]) => void {
return (newHistory) => {
): (newHistory: IHistoryState[], historyCurrentStep?: number) => void {
return (newHistory, historyCurrentStep?: number) => {
setHistory(newHistory);
setHistoryCurrentStep(newHistory.length - 1);
setHistoryCurrentStep(historyCurrentStep !== undefined && historyCurrentStep !== null ? historyCurrentStep : newHistory.length - 1);
};
}