Handle post deletions by removing from active views (close #37)
This commit is contained in:
parent
ace0e6bfd9
commit
ebc2033d18
7 changed files with 59 additions and 4 deletions
|
@ -166,6 +166,7 @@ export class FeedItemModel {
|
|||
did: this.post.author.did,
|
||||
rkey: new AtUri(this.post.uri).rkey,
|
||||
})
|
||||
this.rootStore.emitPostDeleted(this.post.uri)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,6 +256,14 @@ export class FeedModel {
|
|||
this._loadPromise = undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any event listeners. Returns a cleanup function.
|
||||
*/
|
||||
registerListeners() {
|
||||
const sub = this.rootStore.onPostDeleted(this.onPostDeleted.bind(this))
|
||||
return () => sub.remove()
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset and load
|
||||
*/
|
||||
|
@ -303,7 +312,7 @@ export class FeedModel {
|
|||
}
|
||||
|
||||
/**
|
||||
* Check if new postrs are available
|
||||
* Check if new posts are available
|
||||
*/
|
||||
async checkForLatest() {
|
||||
if (this.hasNewLatest) {
|
||||
|
@ -322,6 +331,20 @@ export class FeedModel {
|
|||
this.setHasNewLatest(hasNewLatest)
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes posts from the feed upon deletion.
|
||||
*/
|
||||
onPostDeleted(uri: string) {
|
||||
console.log('hit', uri)
|
||||
let i
|
||||
do {
|
||||
i = this.feed.findIndex(item => item.post.uri === uri)
|
||||
if (i !== -1) {
|
||||
this.feed.splice(i, 1)
|
||||
}
|
||||
} while (i !== -1)
|
||||
}
|
||||
|
||||
// state transitions
|
||||
// =
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue