svg-layout-designer-react/src/Components/History/History.tsx
Siklos 7ff411b988
All checks were successful
continuous-integration/drone/push Build is passing
Implement webworker for save operation + Limit the history size (#29)
- Implement webworker for save operation
- Limit the history size

Reviewed-on: https://git.siklos-chaneru.duckdns.org/Siklos/svg-layout-designer-react/pulls/29
2022-08-15 11:52:17 -04:00

55 lines
1.6 KiB
TypeScript

import * as React from 'react';
import { FixedSizeList as List } from 'react-window';
import { IHistoryState } from '../../Interfaces/IHistoryState';
interface IHistoryProps {
history: IHistoryState[]
historyCurrentStep: number
isOpen: boolean
jumpTo: (move: number) => void
}
export const History: React.FC<IHistoryProps> = (props: IHistoryProps) => {
const isOpenClasses = props.isOpen ? 'right-0' : '-right-64';
const Row = ({ index, style }: {index: number, style: React.CSSProperties}): JSX.Element => {
const reversedIndex = (props.history.length - 1) - index;
const step = props.history[reversedIndex];
const desc = step.LastAction;
const selectedClass = reversedIndex === props.historyCurrentStep
? 'bg-blue-500 hover:bg-blue-600'
: 'bg-slate-500 hover:bg-slate-700';
return (
<button
key={reversedIndex}
style={style}
onClick={() => props.jumpTo(reversedIndex)}
title={step.LastAction}
className={
`w-full elements-sidebar-row whitespace-pre overflow-hidden
text-left text-sm font-medium transition-all ${selectedClass}`
}
>
{desc}
</button>
);
};
return (
<div className={`fixed flex flex-col bg-slate-300 text-white transition-all h-full w-64 overflow-y-auto z-20 ${isOpenClasses}`}>
<div className='bg-slate-600 font-bold sidebar-title'>
Timeline
</div>
<List
className='List overflow-x-hidden'
itemCount={props.history.length}
itemSize={35}
height={window.innerHeight}
width={256}
>
{ Row }
</List>
</div>
);
};