aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/UndoStack.tsx
blob: 32b97b31ad53265695a0996b0036ad9067143c55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { Tooltip } from '@mui/material';
import { Popup, Type } from '@dash/components';
import { observer } from 'mobx-react';
import * as React from 'react';
import { StrCast } from '../../fields/Types';
import { SettingsManager } from '../util/SettingsManager';
import { UndoManager } from '../util/UndoManager';
import './UndoStack.scss';

interface UndoStackProps {}
@observer
export class UndoStack extends React.Component<UndoStackProps> {
    render() {
        const background = UndoManager.batchCounter.get() ? 'yellow' : SettingsManager.userVariantColor;
        const color = UndoManager.batchCounter.get() ? 'black' : SettingsManager.userColor;
        return (
            <Tooltip title="undo stack (if it stays yellow, undo is broken - you should reload Dash)">
                <div>
                    <div className="undoStack-outerContainer">
                        <Popup
                            text="stack"
                            color={color}
                            background={background}
                            placement="top-start"
                            type={Type.TERT}
                            popup={
                                <div
                                    className="undoStack-commandsContainer"
                                    ref={r => r?.scroll({ behavior: 'auto', top: (r?.scrollHeight ?? 0) + 20 })}
                                    style={{
                                        background,
                                        color,
                                    }}>
                                    {Array.from(UndoManager.undoStackNames).map((name, i) => (
                                        <div
                                            className="undoStack-resultContainer"
                                            // eslint-disable-next-line react/no-array-index-key
                                            key={i}
                                            onClick={() => {
                                                const size = UndoManager.undoStackNames.length;
                                                for (let n = 0; n < size - i; n++) UndoManager.Undo();
                                            }}>
                                            <div className="undoStack-commandString">{StrCast(name).replace(/[^.]*\./, '')}</div>
                                        </div>
                                    ))}
                                    {Array.from(UndoManager.redoStackNames)
                                        .reverse()
                                        .map((name, i) => (
                                            <div
                                                className="undoStack-resultContainer"
                                                // eslint-disable-next-line react/no-array-index-key
                                                key={i}
                                                onClick={() => {
                                                    for (let n = 0; n <= i; n++) UndoManager.Redo();
                                                }}>
                                                <div className="undoStack-commandString" style={{ fontWeight: 'bold', background: SettingsManager.userBackgroundColor, color: SettingsManager.userColor }}>
                                                    {StrCast(name).replace(/[^.]*\./, '')}
                                                </div>
                                            </div>
                                        ))}
                                </div>
                            }
                        />
                    </div>
                </div>
            </Tooltip>
        );
    }
}