Browse Source

Fix rendering bug

Carsten Porth 5 years ago
parent
commit
06792841ca
1 changed files with 15 additions and 8 deletions
  1. 15 8
      app/src/components/tweet-actions/tweet-actions.ts

+ 15 - 8
app/src/components/tweet-actions/tweet-actions.ts

@@ -1,4 +1,4 @@
-import { Component, Input } from "@angular/core";
+import { Component, Input, ChangeDetectorRef } from "@angular/core";
 import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api";
 
 /**
@@ -15,21 +15,28 @@ export class TweetActionsComponent {
   @Input()
   data: any[];
 
-  constructor(private twitter: TwitterApiProvider) {}
+  constructor(
+    private twitter: TwitterApiProvider,
+    private ref: ChangeDetectorRef
+  ) {}
 
   like(id) {
     if (!this.data["private_tweet"]) {
-      this.twitter.likeTweet(id);
-      this.data["favorited"] = true;
-      this.data["favorite_count"]++;
+      this.twitter.likeTweet(id).then(() => {
+        this.data["favorited"] = true;
+        this.data["favorite_count"]++;
+        this.ref.detectChanges();
+      });
     }
   }
 
   removeLike(id) {
     if (!this.data["private_tweet"]) {
-      this.twitter.unlikeTweet(id);
-      this.data["favorited"] = false;
-      this.data["favorite_count"]--;
+      this.twitter.unlikeTweet(id).then(() => {
+        this.data["favorited"] = false;
+        this.data["favorite_count"]--;
+        this.ref.detectChanges();
+      });
     }
   }
 }