about summary refs log tree commit diff
path: root/src/state/models/post-thread-view.ts
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-01-18 16:45:48 -0600
committerPaul Frazee <pfrazee@gmail.com>2023-01-18 16:45:48 -0600
commitebc2033d186af6cf81f9533082857ee4a8fa6822 (patch)
treee3438b8bb28d8b8459a6f6346f363628d8cdc623 /src/state/models/post-thread-view.ts
parentace0e6bfd963305c140ecc97d9e82b749066a394 (diff)
downloadvoidsky-ebc2033d186af6cf81f9533082857ee4a8fa6822.tar.zst
Handle post deletions by removing from active views (close #37)
Diffstat (limited to 'src/state/models/post-thread-view.ts')
-rw-r--r--src/state/models/post-thread-view.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/state/models/post-thread-view.ts b/src/state/models/post-thread-view.ts
index 1fc188723..584658e14 100644
--- a/src/state/models/post-thread-view.ts
+++ b/src/state/models/post-thread-view.ts
@@ -173,6 +173,7 @@ export class PostThreadViewPostModel {
       did: this.post.author.did,
       rkey: new AtUri(this.post.uri).rkey,
     })
+    this.rootStore.emitPostDeleted(this.post.uri)
   }
 }
 
@@ -230,6 +231,14 @@ export class PostThreadViewModel {
   }
 
   /**
+   * Register any event listeners. Returns a cleanup function.
+   */
+  registerListeners() {
+    const sub = this.rootStore.onPostDeleted(this.onPostDeleted.bind(this))
+    return () => sub.remove()
+  }
+
+  /**
    * Reset and load
    */
   async refresh() {
@@ -246,6 +255,13 @@ export class PostThreadViewModel {
     this._load()
   }
 
+  /**
+   * Refreshes when posts are deleted
+   */
+  onPostDeleted(_uri: string) {
+    this.refresh()
+  }
+
   // state transitions
   // =