Skip to content

Commit

Permalink
Fix first links in newly created collection not being shown without r…
Browse files Browse the repository at this point in the history
…eload.
  • Loading branch information
muety committed Sep 4, 2019
1 parent 2768870 commit b5692a3
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions public/app/scripts/controllers/collection.js
Expand Up @@ -7,15 +7,24 @@ angular.module('anchrClientApp')
var fetchTitleDebounce = null;

/* Either id or index! */
$scope.setActiveCollection = function(id, index) {
$scope.setActiveCollection = function(id, cached) {
if ($scope.data.active === id) return;
Collection.collection.get({ _id: id }, function(result) {
collections[findCollection(collections, id)] = result;

function setActive() {
$scope.data.active = id;
$window.localStorage.setItem('selectedCollectionId', id);
}, function(err) {
Snackbar.show("Failed to fetch collection " + getCollection(collections, id).name + " from server: " + err.data.error);
});
}

if (!cached) {
Collection.collection.get({ _id: id }, function(result) {
collections[findCollection(collections, id)] = result;
setActive();
}, function(err) {
Snackbar.show("Failed to fetch collection " + getCollection(collections, id).name + " from server: " + err.data.error);
});
} else {
setActive();
}
};

$scope.getCollection = function(id) {
Expand Down Expand Up @@ -71,19 +80,19 @@ angular.module('anchrClientApp')
$scope.addCollection = function(name) {
new Collection.collection({
name: name,
link: []
links: []
}).$save(function(result) {
collections.push(result);
$scope.toggleNewCollection();
$scope.setActiveCollection(result._id);
$scope.clear();
$scope.setActiveCollection(result._id, true);
}, function(err) {
Snackbar.show('Failed to create new collection: ' + err.data.error);
});
};

$scope.shareCollection = function(collId) {
Collection.collection.update({_id: collId, shared: true}, function(result) {
getCollection(collections, collId).sahred = true;
getCollection(collections, collId).shared = true;
Snackbar.show('Collection shared.');
}, function(err) {
Snackbar.show('Failed to share collection: ' + err.data.error);
Expand Down

0 comments on commit b5692a3

Please sign in to comment.