Skip to content

Commit

Permalink
Don't show view switcher until annotations received
Browse files Browse the repository at this point in the history
Don't show the view switcher until the first batch of annotations has
been received. (This first batch will be all the annotations, unless
there are more than 200 annotations of the page.)

This is an attempt to reduce "popping" caused by the annotation switcher
suddenly changing a brief time after first render, when annotations are
loaded:

hypothesis/product-backlog#327 (comment)
  • Loading branch information
seanh committed Jul 5, 2017
1 parent ee080fe commit f240476
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/sidebar/components/test/view-switcher-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ describe('viewSwitcher', function () {
});

beforeEach(function () {
var fakeAnnotationUI = {};
var fakeAnnotationUI = {
getState: sinon.stub().returns({
frames: [
{
// The view switcher only shows after the first batch of
// annotations have been fetched.
isAnnotationFetchComplete: true,
},
],
}),
};
var fakeFeatures = {
flagEnabled: sinon.stub().returns(true),
};
Expand Down
8 changes: 8 additions & 0 deletions src/sidebar/components/view-switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ module.exports = {
return features.flagEnabled('orphans_tab');
};

this.showViewSwitcher = function() {
var frame = annotationUI.getState().frames[0];
if (frame && frame.isAnnotationFetchComplete) {
return true;
}
return false;
};

this.showAnnotationsUnavailableMessage = function () {
return this.selectedTab === this.TAB_ANNOTATIONS &&
this.totalAnnotations === 0 &&
Expand Down
2 changes: 1 addition & 1 deletion src/sidebar/templates/view-switcher.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="view-switcher">
<div class="view-switcher" ng-if="vm.showViewSwitcher()">
<button class="view-switcher__tab"
ng-class="{'is-selected': vm.selectedTab === vm.TAB_ANNOTATIONS}"
h-on-touch="vm.selectTab(vm.TAB_ANNOTATIONS)">
Expand Down

0 comments on commit f240476

Please sign in to comment.