Commit 9629daba authored by Robert Knight's avatar Robert Knight

Avoid showing 'Clear Selection' or 'Clear Search' buttons whilst loading

When loading annotations whilst a search query is active or selection is
present, avoid showing the 'Clear Search' or 'Clear Selection' buttons
until the search has actually completed and we know whether any
annotations match the query or selection.

This fixes the flash of the 'Clear Selection' button when viewing a
direct-linked annotation.
parent fabe1534
......@@ -112,6 +112,10 @@ module.exports = function WidgetController(
searchClient.get({uri: uri, group: group});
}
function isLoading() {
return searchClients.length > 0;
}
/**
* Load annotations for all URLs associated with `frames`.
*
......@@ -175,14 +179,11 @@ module.exports = function WidgetController(
});
$scope.$on(events.GROUP_FOCUSED, function () {
// The focused group may be changed during loading annotations (in which
// case, searchClients.length > 0), as a result of switching to the group
// containing the selected annotation.
// The focused group may be changed during loading annotations as a result
// of switching to the group containing a direct-linked annotation.
//
// In that case, we don't want to trigger reloading annotations again and we
// also want to preserve the selection if the user visits a direct link to a
// group annotation whilst signed out, then signs in.
if (searchClients.length) {
// In that case, we don't want to trigger reloading annotations again.
if (isLoading()) {
return;
}
......@@ -206,7 +207,7 @@ module.exports = function WidgetController(
};
$scope.selectedAnnotationUnavailable = function () {
return searchClients.length === 0 &&
return !isLoading() &&
annotationUI.hasSelectedAnnotations() &&
!threading.idTable[firstKey(annotationUI.selectedAnnotationMap)];
};
......@@ -226,11 +227,13 @@ module.exports = function WidgetController(
// The user is logged out and has landed on a direct linked
// annotation. If there is an annotation selection and that
// selection is available to the user, show the CTA.
return searchClients.length === 0 &&
return !isLoading() &&
annotationUI.hasSelectedAnnotations() &&
!!threading.idTable[firstKey(annotationUI.selectedAnnotationMap)];
};
$scope.isLoading = isLoading;
$rootScope.$on(events.BEFORE_ANNOTATION_CREATED, function (event, data) {
if (data.$highlight || (data.references && data.references.length > 0)) {
return;
......
......@@ -12,7 +12,8 @@
filter-match-count="count('match')"
search-query="search ? search.query : ''"
selection-count="selectedAnnotationsCount"
on-clear-selection="clearSelection()">
on-clear-selection="clearSelection()"
ng-show="!isLoading()">
</search-status-bar>
<li ng-if="isStream">
<sort-dropdown
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment