aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Amoush <mohammad_amoush@brown.edu>2019-06-20 19:16:42 -0400
committerMohammad Amoush <mohammad_amoush@brown.edu>2019-06-20 19:16:42 -0400
commitf4b75a7c921181faeeee04fbd57cd24fbd57523e (patch)
tree5b546f073a8be0dedfcae78f2ca460d73249e947
parente88538bb8af2ba648da2326d0f6edd3e0186766e (diff)
Undo/Redo First Version
-rw-r--r--src/client/views/presentationview/PresentationView.tsx36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/client/views/presentationview/PresentationView.tsx b/src/client/views/presentationview/PresentationView.tsx
index 905117cd1..03e33dad7 100644
--- a/src/client/views/presentationview/PresentationView.tsx
+++ b/src/client/views/presentationview/PresentationView.tsx
@@ -15,6 +15,7 @@ import { library } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faArrowRight, faArrowLeft, faPlay, faStop, faPlus, faTimes, faMinus, faEdit } from '@fortawesome/free-solid-svg-icons';
import { Docs } from "../../documents/Documents";
+import { undoBatch, UndoManager } from "../../util/UndoManager";
library.add(faArrowLeft);
library.add(faArrowRight);
@@ -560,11 +561,13 @@ export class PresentationView extends React.Component<PresViewProps> {
if (castedGroupDocs !== undefined) {
castedGroupDocs.forEach(async (groupDoc: Doc, index: number) => {
let castedGrouping = await DocListCastAsync(groupDoc.grouping);
+ // UndoManager.RunInBatch(() => {
if (castedGrouping) {
castedGrouping.forEach((doc: Doc) => {
doc.presentId = Utils.GenerateGuid();
});
}
+ // }, "guid assignment");
});
}
}
@@ -742,27 +745,54 @@ export class PresentationView extends React.Component<PresViewProps> {
* list. Sets up the next presentation as current.
*/
@action
- removePresentation = () => {
+ removePresentation = async () => {
if (this.presentationsMapping.size !== 1) {
let presentationList = Cast(this.props.Documents, listSpec(Doc));
+ let batch = UndoManager.StartBatch("presRemoval");
let removedDoc = this.presentationsMapping.get(this.currentSelectedPresValue!);
+ presentationList!.splice(presentationList!.indexOf(removedDoc!), 1);
this.presentationsKeyMapping.delete(removedDoc!);
this.presentationsMapping.delete(this.currentSelectedPresValue!);
let remainingPresentations = this.presentationsMapping.values();
let nextDoc = remainingPresentations.next().value;
+
+
+ let curGuid = this.currentSelectedPresValue!;
+ let curPresStatus = this.presStatus;
+ UndoManager.AddEvent({
+ undo: action(() => {
+ this.curPresentation = removedDoc!;
+ this.presStatus = curPresStatus;
+ this.presentationsMapping.set(curGuid, removedDoc!);
+ this.presentationsKeyMapping.set(removedDoc!, curGuid);
+ this.currentSelectedPresValue = curGuid;
+ this.setPresentationBackUps();
+
+ }),
+ redo: action(() => {
+ this.curPresentation = nextDoc;
+ this.presStatus = false;
+ this.presentationsKeyMapping.delete(removedDoc!);
+ this.presentationsMapping.delete(curGuid);
+ this.currentSelectedPresValue = this.presentationsKeyMapping.get(nextDoc)!.toString();
+ this.setPresentationBackUps();
+
+ }),
+ });
+
this.curPresentation = nextDoc;
this.resetGroupIds();
this.resetPresentation();
this.currentSelectedPresValue = this.presentationsKeyMapping.get(nextDoc)!.toString();
this.setPresentationBackUps();
- presentationList!.splice(presentationList!.indexOf(removedDoc!), 1);
+ batch.end();
}
}
/**
* The function that is called to change title of presentation to what user entered.
*/
- @action
+ @undoBatch
changePresentationTitle = (newTitle: string) => {
if (newTitle === "") {
return;