Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop polling issues when creating new team response #1283

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading