Skip to content

Commit

Permalink
Stop polling issues when creating new team res (#1283)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nknguyenhc authored Oct 25, 2024
1 parent 6830c82 commit ef2d08d
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/app/core/services/issue.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export class IssueService {
private issuesPollSubscription: Subscription;
/** Whether the IssueService is downloading the data from Github*/
public isLoading = new BehaviorSubject<boolean>(false);
/** Whether the IssueService is creating a new team response */
private isCreatingTeamResponse = false;

constructor(
private githubService: GithubService,
Expand Down Expand Up @@ -80,15 +82,19 @@ export class IssueService {
*/
pollIssue(issueId: number): Observable<Issue> {
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))
);
}
)
);
}
Expand Down Expand Up @@ -193,11 +199,13 @@ export class IssueService {

createTeamResponse(issue: Issue): Observable<Issue> {
// 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);
Expand Down

0 comments on commit ef2d08d

Please sign in to comment.