Fix duplicate notifications

This commit is contained in:
Yura Bondarenko
2021-06-18 13:59:39 +02:00
parent a3ba4e59b3
commit 7670ba8a43
2 changed files with 15 additions and 13 deletions

View File

@@ -2,7 +2,7 @@ import { Component, Input, OnChanges } from '@angular/core';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { Observable, of as observableOf, Subscription } from 'rxjs'; import { Observable, of as observableOf, Subscription } from 'rxjs';
import { first } from 'rxjs/operators'; import { first, take } from 'rxjs/operators';
import { SectionsService } from '../../sections/sections.service'; import { SectionsService } from '../../sections/sections.service';
import { hasValue, isEmpty, isNotEmpty } from '../../../shared/empty.util'; import { hasValue, isEmpty, isNotEmpty } from '../../../shared/empty.util';
@@ -131,16 +131,18 @@ export class SubmissionUploadFilesComponent implements OnChanges {
.forEach((sectionId) => { .forEach((sectionId) => {
const sectionData = normalizeSectionData(sections[sectionId]); const sectionData = normalizeSectionData(sections[sectionId]);
const sectionErrors = errorsList[sectionId]; const sectionErrors = errorsList[sectionId];
this.sectionService.isSectionType(this.submissionId, sectionId, SectionsType.Upload).subscribe((isUpload) => { this.sectionService.isSectionType(this.submissionId, sectionId, SectionsType.Upload)
if (isUpload) { .pipe(take(1))
// Look for errors on upload .subscribe((isUpload) => {
if ((isEmpty(sectionErrors))) { if (isUpload) {
this.notificationsService.success(null, this.translate.get('submission.sections.upload.upload-successful')); // Look for errors on upload
} else { if ((isEmpty(sectionErrors))) {
this.notificationsService.error(null, this.translate.get('submission.sections.upload.upload-failed')); this.notificationsService.success(null, this.translate.get('submission.sections.upload.upload-successful'));
} } else {
} this.notificationsService.error(null, this.translate.get('submission.sections.upload.upload-failed'));
}); }
}
});
this.sectionService.updateSectionData(this.submissionId, sectionId, sectionData, sectionErrors); this.sectionService.updateSectionData(this.submissionId, sectionId, sectionData, sectionErrors);
}); });
} }

View File

@@ -338,8 +338,8 @@ export class SectionsService {
return this.store.select(submissionObjectFromIdSelector(submissionId)).pipe( return this.store.select(submissionObjectFromIdSelector(submissionId)).pipe(
filter((submissionState: SubmissionObjectEntry) => isNotUndefined(submissionState)), filter((submissionState: SubmissionObjectEntry) => isNotUndefined(submissionState)),
map((submissionState: SubmissionObjectEntry) => { map((submissionState: SubmissionObjectEntry) => {
return isNotUndefined(submissionState.sections) && isNotUndefined(submissionState.sections[sectionId] return isNotUndefined(submissionState.sections) && isNotUndefined(submissionState.sections[sectionId])
&& submissionState.sections[sectionId].sectionType === sectionType ); && submissionState.sections[sectionId].sectionType === sectionType;
}), }),
distinctUntilChanged()); distinctUntilChanged());
} }