Skip to content

Commit

Permalink
DEV: removed code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Tschaika committed Jun 30, 2024
1 parent fb7a5e6 commit 1563dd4
Showing 1 changed file with 21 additions and 39 deletions.
60 changes: 21 additions & 39 deletions src/app/dialogs/add-blinds/add-blinds.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,45 +130,27 @@ export class AddBlindsComponent extends BaseAddDialogComponent<AddAddonComponent
positions.push(i);
}

if (this.data.tournament) {
this.tournamentApiService.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();
}

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();
}
}

Expand Down

0 comments on commit 1563dd4

Please sign in to comment.