From 81fba46a866ff558f9e1ff9ca250f9ade35ccc0a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de>
Date: Thu, 15 Aug 2019 15:20:19 +0200
Subject: [PATCH] Remove rejected comments of indexedDB

---
 .../shared/comment-list/comment-list.component.ts   | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/app/components/shared/comment-list/comment-list.component.ts b/src/app/components/shared/comment-list/comment-list.component.ts
index b867612a4..dceb5b49d 100644
--- a/src/app/components/shared/comment-list/comment-list.component.ts
+++ b/src/app/components/shared/comment-list/comment-list.component.ts
@@ -156,7 +156,6 @@ export class CommentListComponent implements OnInit {
         c.id = payload.id;
         c.timestamp = payload.timestamp;
         this.addComment(c);
-        this.updateComments();
         break;
       case 'CommentPatched':
         // ToDo: Use a map for comments w/ key = commentId
@@ -166,34 +165,36 @@ export class CommentListComponent implements OnInit {
               switch (key) {
                 case this.read:
                   this.comments[i].read = <boolean>value;
+                  this.updateDatabase();
                   break;
                 case this.correct:
                   this.comments[i].correct = <boolean>value;
+                  this.updateDatabase();
                   break;
                 case this.favorite:
                   this.comments[i].favorite = <boolean>value;
+                  this.updateDatabase();
                   break;
                 case 'score':
                   this.comments[i].score = <number>value;
+                  this.updateDatabase();
                   break;
                 case this.ack:
                   const isNowAck = <boolean>value;
                   if (!isNowAck) {
-                    this.comments = this.comments.filter(function (el) {
-                      return el.id !== payload.id;
-                    });
+                    this.deleteComment(payload.id);
                   }
               }
             }
           }
         }
-        this.updateDatabase();
         break;
       case 'CommentHighlighted':
         // ToDo: Use a map for comments w/ key = commentId
         for (let i = 0; i < this.comments.length; i++) {
           if (payload.id === this.comments[i].id) {
             this.comments[i].highlighted = <boolean>payload.lights;
+            this.updateDatabase();
           }
         }
         break;
@@ -227,10 +228,12 @@ export class CommentListComponent implements OnInit {
 
   addComment(comment: Comment): void {
     this.databaseService.comments.add(comment);
+    this.updateComments();
   }
 
   deleteComment(id: string) {
     this.databaseService.comments.delete(id);
+    this.updateComments();
   }
 
   async updateComments() {
-- 
GitLab