Implement history form
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Siklos 2022-08-04 11:17:59 +02:00
parent fab40f5cf7
commit 964d9a0e57
2 changed files with 38 additions and 1 deletions

View file

@ -1,4 +1,4 @@
import React from 'react'; import React, { Children } from 'react';
import './App.scss'; import './App.scss';
import Sidebar from './Components/Sidebar/Sidebar'; import Sidebar from './Components/Sidebar/Sidebar';
import { ElementsSidebar } from './Components/ElementsSidebar/ElementsSidebar'; import { ElementsSidebar } from './Components/ElementsSidebar/ElementsSidebar';
@ -6,6 +6,7 @@ import { AvailableContainer } from './Interfaces/AvailableContainer';
import { Configuration } from './Interfaces/Configuration'; import { Configuration } from './Interfaces/Configuration';
import { Container } from './Components/SVG/Elements/Container'; import { Container } from './Components/SVG/Elements/Container';
import { SVG } from './Components/SVG/SVG'; import { SVG } from './Components/SVG/SVG';
import { History } from './Components/History/History';
interface IAppProps { interface IAppProps {
} }
@ -255,6 +256,12 @@ class App extends React.Component<IAppProps> {
} as IAppState); } as IAppState);
} }
public jumpTo(move: number): void {
this.setState({
historyCurrentStep: move
} as IAppState);
}
/** /**
* Render the application * Render the application
* @returns {JSX.Element} Rendered JSX element * @returns {JSX.Element} Rendered JSX element
@ -282,6 +289,7 @@ class App extends React.Component<IAppProps> {
<SVG selected={current.SelectedContainer}> <SVG selected={current.SelectedContainer}>
{ current.MainContainer } { current.MainContainer }
</SVG> </SVG>
<History history={this.state.history} jumpTo={(move) => { this.jumpTo(move); }} />
</div> </div>
); );
} }

View file

@ -0,0 +1,29 @@
import * as React from 'react';
import { IHistoryState } from '../../App';
interface IHistoryProps {
history: IHistoryState[],
jumpTo: (move: number) => void
}
export class History extends React.Component<IHistoryProps> {
public render() {
const states = this.props.history.map((step, move) => {
const desc = move
? `Go back at turn n°${move}`
: 'Go back at the beginning';
return (
<li key={move}>
<button onClick={() => this.props.jumpTo(move)}>{desc}</button>
</li>
);
});
return (
<div>
{ states }
</div>
);
}
}