Skip to content

Commit

Permalink
#657 Error when deleting comments on first go, ok after that
Browse files Browse the repository at this point in the history
  • Loading branch information
schoicsiro committed Oct 13, 2023
1 parent 11fee72 commit ace1bb7
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ profileEditor.controller('CommentController', function (profileService, util, co
var self = this;

self.comments = [];
self.savedComments = [];
self.currentComment = null;
self.opusId = util.getEntityId("opus");
self.profileId = util.getEntityId("profile");
Expand All @@ -19,6 +20,7 @@ profileEditor.controller('CommentController', function (profileService, util, co
var promise = profileService.getComments(self.opusId, self.profileId);
promise.then(function(data) {
self.comments = orderBy(data, 'dateCreated');
self.savedComments = orderBy(data, 'dateCreated');
})
};

Expand Down Expand Up @@ -78,8 +80,10 @@ profileEditor.controller('CommentController', function (profileService, util, co
} else {
if (!Array.isArray(self.comments)) {
self.comments = [];
self.savedComments = []
}
self.comments.push(data);
self.savedComments.push(data);
}

self.currentComment = null;
Expand All @@ -89,9 +93,13 @@ profileEditor.controller('CommentController', function (profileService, util, co
};

function find(path) {
var array = self.comments;
// var array = self.comments;
var array = self.savedComments;
var comment = null;
angular.forEach(path, function(index) {
if (index > array.length-1) {
index = array.length-1
}
comment = array[index];
if (comment.children) {
array = orderBy(comment.children, 'dateCreated');
Expand All @@ -117,7 +125,16 @@ profileEditor.controller('CommentController', function (profileService, util, co

comment.children.splice(lastIndex, 1);
} else {
self.comments.splice(path[0], 1);
let selectedComment = self.savedComments[path[0]]
let filterdComments = self.comments.filter(i => i !== selectedComment)
self.comments = filterdComments;
// if (self.comments.length === 1) {
// self.comments.splice(0,1);
// } else if (self.comments.length < path[0]){
// self.comments.splice(path[0]-1, 1);
// } else {
// self.comments.splice(path[0], 1);
// }
}
}
});

0 comments on commit ace1bb7

Please sign in to comment.