Skip to content

Commit

Permalink
(FatalBadgers#1) Resolve user promise to prevent race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
scottrice10 committed Feb 6, 2015
1 parent af4228c commit a81d8f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
27 changes: 16 additions & 11 deletions client/app/search/search.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,31 @@ angular.module('tikrApp')
$scope.users = [];
$scope.searchStarted = false;
$scope.selected = 'javascript';
var user = Auth.getCurrentUser();

// returns a promise
$scope.fetchUsers = function(language, pageNumber) {
$scope.selected = language;
User.search({
skill: language,
username: $scope.TEST_USER || Auth.getCurrentUser().github.login,
pageNumber: pageNumber
}, function(data) {
$scope.searchStarted = true;
$scope.data = data[0];
$scope.users = $scope.data.items;
});

user.$promise
.then(function(user){
User.search({
skill: language,
username: $scope.TEST_USER || user.github.login,
pageNumber: pageNumber
}, function(data) {
$scope.searchStarted = true;
$scope.data = data[0];
$scope.users = $scope.data.items;
});
});
};

$scope.entry = {};
$scope.languages = [];
$scope.refreshTypeahead = function(input) {
$scope.languages = [];

$http.get('/api/languages').success(function(data) {
$scope.languages = [];
data.forEach(function(language) {
$scope.languages.push(language.Name);
});
Expand Down
2 changes: 1 addition & 1 deletion client/components/auth/auth.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,4 @@ angular.module('tikrApp')
return $cookieStore.get('token');
}
};
});
});

0 comments on commit a81d8f2

Please sign in to comment.