Skip to content

Commit

Permalink
Fix: only show newly created annotation dialog on hover (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum authored Nov 10, 2017
1 parent b21ed0e commit 0ba1965
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/AnnotationThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ class AnnotationThread extends EventEmitter {
const tempAnnotation = new Annotation(tempAnnotationData);
this.saveAnnotationToThread(tempAnnotation);

// Changing state from pending
this.state = STATES.hover;

// Save annotation on server
return this.annotationService
.create(annotationData)
Expand Down Expand Up @@ -499,7 +496,11 @@ class AnnotationThread extends EventEmitter {
this.dialog.removeAnnotation(tempAnnotation.annotationID);
}

this.showDialog();
if (this.isMobile) {
// Changing state from pending
this.state = STATES.hover;
this.showDialog();
}
this.emit(THREAD_EVENT.save);
}

Expand Down
19 changes: 17 additions & 2 deletions src/__tests__/AnnotationThread-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ describe('AnnotationThread', () => {
threadNumber: '1'
})
);
expect(thread.state).to.equal(STATES.hover);
});

it('should delete the temporary annotation and broadcast an error if there was an error saving', (done) => {
Expand Down Expand Up @@ -210,7 +209,6 @@ describe('AnnotationThread', () => {
stubs.create = sandbox.stub(annotationService, 'create');
stubs.saveAnnotationToThread = sandbox.stub(thread, 'saveAnnotationToThread');
sandbox.stub(thread, 'getThreadEventData').returns({});
sandbox.stub(thread, 'showDialog');
});

it('should save annotation to thread if it does not exist in annotations array', () => {
Expand Down Expand Up @@ -243,6 +241,23 @@ describe('AnnotationThread', () => {

thread.updateTemporaryAnnotation(tempAnnotation, serverAnnotation);
});

it('should only show dialog immediately on mobile devices', () => {
const serverAnnotation = { threadNumber: 1 };
const tempAnnotation = serverAnnotation;
sandbox.stub(thread, 'showDialog');

// Don't show dialog on web browsers
thread.updateTemporaryAnnotation(tempAnnotation, serverAnnotation);
expect(thread.showDialog).to.not.be.called;
expect(thread.state).not.equals(STATES.hover);

// Only show dialog on mobile browsers
thread.isMobile = true;
thread.updateTemporaryAnnotation(tempAnnotation, serverAnnotation);
expect(thread.showDialog).to.be.called;
expect(thread.state).equals(STATES.hover);
});
})

describe('deleteAnnotation()', () => {
Expand Down

0 comments on commit 0ba1965

Please sign in to comment.