From 1563dd4e7e52393c57f2d55465f9d11e6f4fc29d Mon Sep 17 00:00:00 2001 From: Tschaika Date: Sun, 30 Jun 2024 14:01:14 +0200 Subject: [PATCH] DEV: removed code duplication --- .../add-blinds/add-blinds.component.ts | 60 +++++++------------ 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/src/app/dialogs/add-blinds/add-blinds.component.ts b/src/app/dialogs/add-blinds/add-blinds.component.ts index 6506bf3..7ab886f 100644 --- a/src/app/dialogs/add-blinds/add-blinds.component.ts +++ b/src/app/dialogs/add-blinds/add-blinds.component.ts @@ -130,45 +130,27 @@ export class AddBlindsComponent extends BaseAddDialogComponent this.fetchService.trigger()), - tap(() => { - if (this.dialogRef) { - this.dialogRef.close({ - blindId: model.blindIds - }); - } - - this.isLoadingAdd = false; - }), - catchError(() => { - this.isLoadingAdd = false; - return of(null); - }) - ).subscribe(); - } - - if (this.data.structure) { - this.blindStructureApiService.addBlinds$(model.blindIds, model.parentId, positions).pipe( - take(1), - tap((a) => this.fetchService.trigger()), - tap(() => { - if (this.dialogRef) { - this.dialogRef.close({ - blindId: model.blindIds - }); - } - - this.isLoadingAdd = false; - }), - catchError(() => { - this.isLoadingAdd = false; - return of(null); - }) - ).subscribe(); - } + const action$ = this.data.tournament + ? this.tournamentApiService.addBlinds$(model.blindIds, model.parentId, positions) + : this.blindStructureApiService.addBlinds$(model.blindIds, model.parentId, positions); + + action$.pipe( + take(1), + tap((a) => this.fetchService.trigger()), + tap(() => { + if (this.dialogRef) { + this.dialogRef.close({ + blindId: model.blindIds + }); + } + + this.isLoadingAdd = false; + }), + catchError(() => { + this.isLoadingAdd = false; + return of(null); + }) + ).subscribe(); } }