From ef2d08da940527f64f53d68632fb752b5352a0c5 Mon Sep 17 00:00:00 2001 From: Nguyen <87511888+nknguyenhc@users.noreply.github.com> Date: Fri, 25 Oct 2024 23:11:04 +0800 Subject: [PATCH] Stop polling issues when creating new team res (#1283) Before this, team response might be created at right the moment the issue is being polled. This causes the error message to pops up, as request to update label has been processed, but request to create comment has not. --- src/app/core/services/issue.service.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/app/core/services/issue.service.ts b/src/app/core/services/issue.service.ts index a8fd96cc2..49b1e1b05 100644 --- a/src/app/core/services/issue.service.ts +++ b/src/app/core/services/issue.service.ts @@ -36,6 +36,8 @@ export class IssueService { private issuesPollSubscription: Subscription; /** Whether the IssueService is downloading the data from Github*/ public isLoading = new BehaviorSubject(false); + /** Whether the IssueService is creating a new team response */ + private isCreatingTeamResponse = false; constructor( private githubService: GithubService, @@ -80,15 +82,19 @@ export class IssueService { */ pollIssue(issueId: number): Observable { return timer(0, IssueService.POLL_INTERVAL).pipe( - exhaustMap(() => - this.githubService.fetchIssueGraphql(issueId).pipe( - map((response) => { - const issue = this.createIssueModel(response); - this.updateLocalStore(issue); - return issue; - }), - catchError((err) => this.getIssue(issueId)) - ) + exhaustMap(() => { + if (this.isCreatingTeamResponse) { + return EMPTY; + } + return this.githubService.fetchIssueGraphql(issueId).pipe( + map((response) => { + const issue = this.createIssueModel(response); + this.updateLocalStore(issue); + return issue; + }), + catchError((err) => this.getIssue(issueId)) + ); + } ) ); } @@ -193,11 +199,13 @@ export class IssueService { createTeamResponse(issue: Issue): Observable { // The issue must be updated first to ensure that fields like assignees are valid + this.isCreatingTeamResponse = true; const teamResponse = issue.createGithubTeamResponse(); return this.updateGithubIssue(issue).pipe( mergeMap((response: GithubIssue) => { return this.githubService.createIssueComment(issue.id, teamResponse).pipe( map((githubComment: GithubComment) => { + this.isCreatingTeamResponse = false; issue.githubComments = [githubComment, ...issue.githubComments.filter((c) => c.id !== githubComment.id)]; response.comments = issue.githubComments; return this.createIssueModel(response);