Skip to content

Commit

Permalink
Fix: Reset undo/redo buttons on drawing save/delete (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum committed Dec 4, 2018
1 parent 6d71dee commit 441f0f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/controllers/DrawingModeController.js
Expand Up @@ -283,6 +283,9 @@ class DrawingModeController extends AnnotationModeController {

this.bindListeners();

// Reset undo/redo buttons
this.updateUndoRedoButtonEls();

// Given a location (page change) start drawing at the provided location
if (eventData && eventData.location) {
// $FlowFixMe
Expand All @@ -299,6 +302,9 @@ class DrawingModeController extends AnnotationModeController {
thread.removeListener('threadevent', this.handleThreadEvents);
thread.unbindDrawingListeners();

// Reset undo/redo buttons
this.updateUndoRedoButtonEls();

if (thread.state === STATES.pending) {
// Soft delete, in-progress thread doesn't require a redraw or a delete on the server
// Clear in-progress thread and restart drawing
Expand Down Expand Up @@ -405,7 +411,7 @@ class DrawingModeController extends AnnotationModeController {
* @param {number} redoCount - Thenumber of objects that can be redone
* @return {void}
*/
updateUndoRedoButtonEls(undoCount: number, redoCount: number): void {
updateUndoRedoButtonEls(undoCount: number = 0, redoCount: number = 0): void {
if (this.undoButtonEl) {
if (undoCount === 1) {
enableElement(this.undoButtonEl);
Expand Down
4 changes: 4 additions & 0 deletions src/controllers/__tests__/DrawingModeController-test.js
Expand Up @@ -265,6 +265,7 @@ describe('controllers/DrawingModeController', () => {
expect(controller.unbindListeners).toBeCalled();
expect(controller.bindListeners).toBeCalled();
expect(controller.currentThread).toBeUndefined();
expect(controller.updateUndoRedoButtonEls).toBeCalled();
expect(thread.handleStart).not.toBeCalled();
expect(thread.removeListener).toBeCalledWith('threadevent', expect.any(Function));
expect(thread.unbindDrawingListeners).toBeCalled();
Expand All @@ -278,6 +279,7 @@ describe('controllers/DrawingModeController', () => {
expect(controller.unbindListeners).toBeCalled();
expect(controller.bindListeners).toBeCalled();
expect(controller.currentThread).toBeUndefined();
expect(controller.updateUndoRedoButtonEls).toBeCalled();
expect(thread.destroy).toBeCalled();
expect(thread.removeListener).toBeCalledWith('threadevent', expect.any(Function));
expect(thread.unbindDrawingListeners).toBeCalled();
Expand All @@ -293,6 +295,7 @@ describe('controllers/DrawingModeController', () => {
});
expect(controller.unregisterThread).toBeCalled();
expect(controller.currentThread).toBeUndefined();
expect(controller.updateUndoRedoButtonEls).toBeCalled();
expect(thread.removeListener).toBeCalledWith('threadevent', expect.any(Function));
expect(thread.unbindDrawingListeners).toBeCalled();
});
Expand All @@ -307,6 +310,7 @@ describe('controllers/DrawingModeController', () => {
});
expect(controller.unbindListeners).toBeCalled();
expect(controller.bindListeners).toBeCalled();
expect(controller.updateUndoRedoButtonEls).toBeCalled();
expect(thread.destroy).toBeCalled();
});
});
Expand Down

0 comments on commit 441f0f2

Please sign in to comment.