Skip to content

Commit 000e314

Browse files
authored
Merge pull request #1443 from rohit645/total_items_on_delete
fixed total no of posts not updating on deleting a post fixes #3326
2 parents bbc5bfa + 5d3f2d7 commit 000e314

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

app/main/posts/common/post-actions.directive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function PostActionsDirective(
4141
$scope.statuses = PostActionsService.getStatuses();
4242
}
4343

44+
// Called when a single data item is deleted.
4445
function deletePost() {
4546
PostActionsService.delete($scope.post).then(function () {
4647
$rootScope.$broadcast('event:edit:post:status:data:mode:saveSuccess', {post: $scope.post, deleted: true});
@@ -52,7 +53,6 @@ function PostActionsDirective(
5253
// only map needs to reload
5354
$state.reload();
5455
}
55-
5656
});
5757
}
5858

app/main/posts/views/post-view-data.directive.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function PostViewDataController(
181181
);
182182

183183
$scope.$on('event:edit:leave:form:complete', function () {
184-
// Bercause there is no state management
184+
// Because there is no state management
185185
// We copy the next Post to be the current Post
186186
// if the previous Post exited correctly
187187
// Ideally Post Card would become a service more akin
@@ -255,9 +255,11 @@ function PostViewDataController(
255255
function removePostFromList(postObj) {
256256
$scope.posts.forEach((post, index) => {
257257
// args.post is the post being updated/saved and sent from the broadcast
258+
// since a single post is being deleted here, reduce count of totalitems by 1.
258259
if (post.id === postObj.id) {
259260
let nextInLine = $scope.posts[index + 1];
260261
$scope.posts.splice(index, 1);
262+
$scope.totalItems = $scope.totalItems - 1;
261263
if ($scope.posts.length) {
262264
groupPosts($scope.posts);
263265
if ($scope.selectedPost.post) {
@@ -329,7 +331,6 @@ function PostViewDataController(
329331
PostEndpoint.query(postQuery).$promise.then(function (postsResponse) {
330332
//Clear posts
331333
clearPosts ? resetPosts() : null;
332-
333334
// If we're loading posts for the first time and we have a selected post (post detail view)
334335
// check to see that the selected post isn't in the list
335336
// and then deselect it and select the first item
@@ -360,6 +361,7 @@ function PostViewDataController(
360361
});
361362
}
362363

364+
// this function is called when multiple data items are deleted
363365
function deletePosts() {
364366
Notify.confirmDelete('notify.post.bulk_destroy_confirm', { count: $scope.selectedPosts.length }).then(function () {
365367
// ask server to delete selected posts

0 commit comments

Comments
 (0)