From c3d1d4101efedfe4dc35587b618dde0a53945b37 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 22 Sep 2016 19:26:20 -0400 Subject: [PATCH] show loading while syncing on vault list --- src/popup/app/current/currentController.js | 2 +- src/popup/app/global/mainController.js | 4 ++-- src/popup/app/vault/vaultController.js | 17 +++++++++-------- src/services/syncService.js | 5 ++++- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/popup/app/current/currentController.js b/src/popup/app/current/currentController.js index f31fe5fc92..1b91752628 100644 --- a/src/popup/app/current/currentController.js +++ b/src/popup/app/current/currentController.js @@ -86,7 +86,7 @@ angular } }; - $scope.$on('syncCompleted', function (event, args) { + $scope.$on('syncCompleted', function (event, successfully) { if ($scope.loaded) { setTimeout(loadVault, 500); } diff --git a/src/popup/app/global/mainController.js b/src/popup/app/global/mainController.js index 167d38690f..01cace075a 100644 --- a/src/popup/app/global/mainController.js +++ b/src/popup/app/global/mainController.js @@ -1,4 +1,4 @@ -angular +angular .module('bit.global') .controller('mainController', function ($scope, $state, loginService, toastr) { @@ -18,7 +18,7 @@ chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) { if (msg.command === 'syncCompleted') { - $scope.$broadcast('syncCompleted'); + $scope.$broadcast('syncCompleted', msg.successfully); } else if (msg.command === 'syncStarted') { $scope.$broadcast('syncStarted'); diff --git a/src/popup/app/vault/vaultController.js b/src/popup/app/vault/vaultController.js index 76d6efe144..5f0c5bd0c4 100644 --- a/src/popup/app/vault/vaultController.js +++ b/src/popup/app/vault/vaultController.js @@ -1,7 +1,8 @@ angular .module('bit.vault') - .controller('vaultController', function ($scope, $rootScope, siteService, folderService, $q, $state, $stateParams, toastr) { + .controller('vaultController', function ($scope, $rootScope, siteService, folderService, $q, $state, $stateParams, toastr, + syncService) { $('#search').focus(); var delayLoad = true; @@ -42,9 +43,11 @@ promises.push(sitePromise); $q.all(promises).then(function () { - $scope.loaded = true; - $rootScope.vaultFolders = decFolders; - $rootScope.vaultSites = decSites; + if (decSites.length || !syncService.syncInProgress) { + $scope.loaded = true; + $rootScope.vaultFolders = decFolders; + $rootScope.vaultSites = decSites; + } if (!delayLoad) { setScrollY(); } @@ -108,10 +111,8 @@ toastr.info(type + ' copied!'); }; - $scope.$on('syncCompleted', function (event, args) { - if ($scope.loaded) { - setTimeout(loadVault, 500); - } + $scope.$on('syncCompleted', function (event, successfully) { + setTimeout(loadVault, 500); }); function getScrollY() { diff --git a/src/services/syncService.js b/src/services/syncService.js index 97d317e3a0..559991530a 100644 --- a/src/services/syncService.js +++ b/src/services/syncService.js @@ -14,15 +14,17 @@ function initSyncService() { throw 'callback function required'; } + syncStarted(); + var self = this; self.userService.isAuthenticated(function (isAuthenticated) { if (!isAuthenticated) { + syncCompleted(false); callback(false); return; } self.userService.getUserId(function (userId) { - syncStarted(); var now = new Date(); var ciphers = self.apiService.getCiphers(function (response) { var sites = {}; @@ -178,6 +180,7 @@ function initSyncService() { } function handleError() { + syncCompleted(false); // TODO: check for unauth or forbidden and logout } };