Skip to content

Commit

Permalink
Refactor posting deletion logic to not abort when deconstructing post…
Browse files Browse the repository at this point in the history
… component
  • Loading branch information
badkeyy committed Nov 27, 2024
1 parent 83ac531 commit 94a8e29
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/webapp/app/shared/metis/posting.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export abstract class PostingDirective<T extends Posting> implements OnInit, OnD
ngOnDestroy(): void {
if (this.deleteTimer !== undefined) {
clearTimeout(this.deleteTimer);
this.deletePostingWithoutTimeout();
}

if (this.deleteInterval !== undefined) {
Expand All @@ -65,11 +66,7 @@ export abstract class PostingDirective<T extends Posting> implements OnInit, OnD

this.deleteTimer = setTimeout(
() => {
if (this.isAnswerPost) {
this.metisService.deleteAnswerPost(this.posting);
} else {
this.metisService.deletePost(this.posting);
}
this.deletePostingWithoutTimeout();
},
// We add a tiny buffer to make it possible for the user to react a bit longer than the ui displays (+1000)
this.deleteTimerInSeconds * 1000 + 1000,
Expand Down Expand Up @@ -131,4 +128,12 @@ export abstract class PostingDirective<T extends Posting> implements OnInit, OnD
this.posting.isSaved = true;
}
}

private deletePostingWithoutTimeout() {
if (this.isAnswerPost) {
this.metisService.deleteAnswerPost(this.posting);
} else {
this.metisService.deletePost(this.posting);
}
}
}

0 comments on commit 94a8e29

Please sign in to comment.