Compare commits

..

No commits in common. "cefeeb54c0f957c37aaaca89b3d9f42087aa28c6" and "704dab7307fb98a0418cdd6df5c43052ee89ad36" have entirely different histories.

4 changed files with 41 additions and 34 deletions

View file

@ -27,15 +27,14 @@ export function SelectContainer(
throw new Error('[SelectContainer] Cannot find container among children of main container!'); throw new Error('[SelectContainer] Cannot find container among children of main container!');
} }
history.push({ setHistory(history.concat([{
LastAction: `Select ${selectedContainer.properties.id}`, LastAction: `Select container ${selectedContainer.properties.id}`,
MainContainer: mainContainerClone, MainContainer: mainContainerClone,
SelectedContainer: selectedContainer, SelectedContainer: selectedContainer,
SelectedContainerId: selectedContainer.properties.id, SelectedContainerId: selectedContainer.properties.id,
TypeCounters: Object.assign({}, current.TypeCounters) TypeCounters: Object.assign({}, current.TypeCounters)
}); }]));
setHistory(history); setHistoryCurrentStep(history.length);
setHistoryCurrentStep(history.length - 1);
} }
/** /**
@ -88,15 +87,14 @@ export function DeleteContainer(
container.parent; container.parent;
const SelectedContainerId = SelectedContainer.properties.id; const SelectedContainerId = SelectedContainer.properties.id;
history.push({ setHistory(history.concat([{
LastAction: `Delete ${containerId}`, LastAction: `Delete container ${containerId}`,
MainContainer: mainContainerClone, MainContainer: mainContainerClone,
SelectedContainer, SelectedContainer,
SelectedContainerId, SelectedContainerId,
TypeCounters: Object.assign({}, current.TypeCounters) TypeCounters: Object.assign({}, current.TypeCounters)
}); }]));
setHistory(history); setHistoryCurrentStep(history.length);
setHistoryCurrentStep(history.length - 1);
} }
/** /**
@ -237,13 +235,12 @@ export function AddContainer(
} }
// Update the state // Update the state
history.push({ setHistory(history.concat([{
LastAction: 'Add container', LastAction: 'Add container',
MainContainer: clone, MainContainer: clone,
SelectedContainer: parentClone, SelectedContainer: parentClone,
SelectedContainerId: parentClone.properties.id, SelectedContainerId: parentClone.properties.id,
TypeCounters: newCounters TypeCounters: newCounters
}); }]));
setHistory(history); setHistoryCurrentStep(history.length);
setHistoryCurrentStep(history.length - 1);
} }

View file

@ -51,15 +51,14 @@ export function OnPropertyChange(
RecalculatePhysics(container); RecalculatePhysics(container);
} }
history.push({ setHistory(history.concat([{
LastAction: `Change ${key} of ${container.properties.id}`, LastAction: `Change property of container ${container.properties.id}`,
MainContainer: mainContainerClone, MainContainer: mainContainerClone,
SelectedContainer: container, SelectedContainer: container,
SelectedContainerId: container.properties.id, SelectedContainerId: container.properties.id,
TypeCounters: Object.assign({}, current.TypeCounters) TypeCounters: Object.assign({}, current.TypeCounters)
}); }]));
setHistory(history); setHistoryCurrentStep(history.length);
setHistoryCurrentStep(history.length - 1);
} }
/** /**
@ -108,13 +107,12 @@ export function OnPropertiesSubmit(
RecalculatePhysics(container); RecalculatePhysics(container);
} }
history.push({ setHistory(history.concat([{
LastAction: `Change properties of ${container.properties.id}`, LastAction: `Change property of container ${container.properties.id}`,
MainContainer: mainContainerClone, MainContainer: mainContainerClone,
SelectedContainer: container, SelectedContainer: container,
SelectedContainerId: container.properties.id, SelectedContainerId: container.properties.id,
TypeCounters: Object.assign({}, current.TypeCounters) TypeCounters: Object.assign({}, current.TypeCounters)
}); }]));
setHistory(history); setHistoryCurrentStep(history.length);
setHistoryCurrentStep(history.length - 1);
} }

View file

@ -97,6 +97,11 @@ export const ElementsSidebar: React.FC<IElementsSidebarProps> = (props: IElement
); );
return () => { return () => {
elementRef.current?.removeEventListener(
'contextmenu',
onContextMenu
);
window.removeEventListener( window.removeEventListener(
'click', 'click',
onLeftClick onLeftClick

View file

@ -1,5 +1,5 @@
import * as React from 'react'; import * as React from 'react';
import { IHistoryState } from '../../Interfaces/IHistoryState'; import { IHistoryState } from "../../Interfaces/IHistoryState";
interface IHistoryProps { interface IHistoryProps {
history: IHistoryState[] history: IHistoryState[]
@ -10,31 +10,38 @@ interface IHistoryProps {
export const History: React.FC<IHistoryProps> = (props: IHistoryProps) => { export const History: React.FC<IHistoryProps> = (props: IHistoryProps) => {
const isOpenClasses = props.isOpen ? 'right-0' : '-right-64'; const isOpenClasses = props.isOpen ? 'right-0' : '-right-64';
const states: JSX.Element[] = [];
for (let move = props.history.length - 1; move >= 0; move--) { const states = props.history.map((step, move) => {
const step = props.history[move];
const desc = move > 0 const desc = move > 0
? `${move}: ${step.LastAction}` ? `Go to modification n°${move}`
: 'Go to the beginning'; : 'Go to the beginning';
const selectedClass = move === props.historyCurrentStep const isCurrent = move === props.historyCurrentStep;
const selectedClass = isCurrent
? 'bg-blue-500 hover:bg-blue-600' ? 'bg-blue-500 hover:bg-blue-600'
: 'bg-slate-500 hover:bg-slate-700'; : 'bg-slate-500 hover:bg-slate-700';
states.push( const isCurrentText = isCurrent
? ' (current)'
: '';
return (
<button <button
key={move} key={move}
onClick={() => props.jumpTo(move)} onClick={() => props.jumpTo(move)}
title={step.LastAction}
className={ className={
`w-full elements-sidebar-row whitespace-pre `w-full elements-sidebar-row whitespace-pre
text-left text-sm font-medium transition-all ${selectedClass}` text-left text-sm font-medium transition-all ${selectedClass}`
} }
> >
{desc} {desc}{isCurrentText}
</button> </button>
); );
} });
// recent first
states.reverse();
return ( return (
<div className={`fixed flex flex-col bg-slate-300 text-white transition-all h-screen w-64 overflow-y-auto z-20 ${isOpenClasses}`}> <div className={`fixed flex flex-col bg-slate-300 text-white transition-all h-screen w-64 overflow-y-auto z-20 ${isOpenClasses}`}>