Skip to content
Permalink
Browse files

Fix first links in newly created collection not being shown without r…

…eload.
  • Loading branch information...
n1try committed Sep 4, 2019
1 parent 2768870 commit b5692a39c0e3b5b0ab1febdb8db569d41b0db688
Showing with 19 additions and 10 deletions.
  1. +19 −10 public/app/scripts/controllers/collection.js
@@ -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) {
@@ -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);

0 comments on commit b5692a3

Please sign in to comment.
You can’t perform that action at this time.