Newer
Older
import React, { ChangeEvent } from "react";
import { saveGraphJson } from "../../../datasets";
import ManagedData from "../structures/manageddata";
import "./historynavigator.css";
type propTypes = {
historyObject: ManagedData;
spaceId: string;
};
export class HistoryNavigator extends React.Component<propTypes> {
constructor(props: propTypes) {
super(props);
this.handleUndo = this.handleUndo.bind(this);
this.handleRedo = this.handleRedo.bind(this);
this.handleSave = this.handleSave.bind(this);
this.handleSelectSavepoint = this.handleSelectSavepoint.bind(this);
}
/**
* Undo a step in the history object.
*/
handleUndo() {
}
/**
* Redo a step in the hisory object.
*/
handleRedo() {
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
}
/**
* Saves current data of history object.
*/
handleSave() {
saveGraphJson(this.props.spaceId, this.props.historyObject.serialize());
// TODO: Save successful?
this.props.historyObject.markChangesAsSaved();
alert(
"Saved! (Though not for sure, currently not checking for success of failure)"
);
}
/**
* Loads selected savepoint into history object.
*/
handleSelectSavepoint(e: ChangeEvent<HTMLSelectElement>) {
if (!this.props.historyObject.goToSavePoint(Number(e.target.value))) {
alert("Something went wrong, could not load savepoint.");
}
}
render(): React.ReactNode {
return (
<div id="history-navigator">
<button onClick={this.handleUndo}>Undo</button>
<button onClick={this.handleRedo}>Redo</button>
<select onChange={this.handleSelectSavepoint}>
{this.props.historyObject
? this.props.historyObject.history.map((savepoint) => {
return (
<option
key={savepoint.id}
value={savepoint.id}
selected={
savepoint.id ===
this.props.historyObject
.currentSavePoint.id
}