fix(sonarr): 🐛 Improved the error handling in the sonarr settings page in the UI

This should hopefully prevent some odd situations where the settings are in a odd state #4877
pull/4881/head^2
tidusjar 1 year ago
parent 605e746fce
commit fcd78fee61

@ -1,7 +1,7 @@
import { Component, OnInit } from "@angular/core"; import { Component, OnInit } from "@angular/core";
import { UntypedFormBuilder, FormControl, UntypedFormGroup, Validators } from "@angular/forms"; import { UntypedFormBuilder, UntypedFormGroup, Validators } from "@angular/forms";
import { SonarrFacade } from "app/state/sonarr/sonarr.facade"; import { SonarrFacade } from "app/state/sonarr/sonarr.facade";
import { finalize, map } from "rxjs"; import { catchError, finalize, map, of } from "rxjs";
import { ILanguageProfiles, ISonarrProfile, ISonarrRootFolder, ITag } from "../../interfaces"; import { ILanguageProfiles, ISonarrProfile, ISonarrRootFolder, ITag } from "../../interfaces";
@ -95,7 +95,7 @@ export class SonarrComponent implements OnInit {
this.tags = []; this.tags = [];
this.animeTags = []; this.animeTags = [];
if (version.length > 0) { if (version?.length > 0) {
this.sonarrVersion = version[0]; this.sonarrVersion = version[0];
} }
@ -132,11 +132,19 @@ export class SonarrComponent implements OnInit {
public getProfiles(form: UntypedFormGroup) { public getProfiles(form: UntypedFormGroup) {
this.profilesRunning = true; this.profilesRunning = true;
this.sonarrService.getQualityProfiles(form.value) this.sonarrService.getQualityProfiles(form.value)
.pipe(catchError((_) => {
this.notificationService.error("Could not load Quality Profiles");
return of([]);
}))
.subscribe(x => { .subscribe(x => {
this.profilesRunning = false;
if (x.length === 0) {
return;
}
this.qualities = x; this.qualities = x;
this.qualitiesAnime = x; this.qualitiesAnime = x;
this.qualities.unshift({ name: "Please Select", id: -1 }); this.qualities.unshift({ name: "Please Select", id: -1 });
this.profilesRunning = false;
this.notificationService.success("Successfully retrieved the Quality Profiles"); this.notificationService.success("Successfully retrieved the Quality Profiles");
}); });
} }
@ -144,12 +152,19 @@ export class SonarrComponent implements OnInit {
public getRootFolders(form: UntypedFormGroup) { public getRootFolders(form: UntypedFormGroup) {
this.rootFoldersRunning = true; this.rootFoldersRunning = true;
this.sonarrService.getRootFolders(form.value) this.sonarrService.getRootFolders(form.value)
.pipe(catchError((_) => {
this.notificationService.error("Could not load Root Folders");
return of([]);
}))
.subscribe(x => { .subscribe(x => {
this.rootFoldersRunning = false;
if (x.length === 0) {
return;
}
this.rootFolders = x; this.rootFolders = x;
this.rootFolders.unshift({ path: "Please Select", id: -1 }); this.rootFolders.unshift({ path: "Please Select", id: -1 });
this.rootFoldersAnime = x; this.rootFoldersAnime = x;
this.rootFoldersRunning = false;
this.notificationService.success("Successfully retrieved the Root Folders"); this.notificationService.success("Successfully retrieved the Root Folders");
}); });
} }
@ -157,11 +172,18 @@ export class SonarrComponent implements OnInit {
public getLanguageProfiles(form: UntypedFormGroup) { public getLanguageProfiles(form: UntypedFormGroup) {
this.langRunning = true; this.langRunning = true;
this.sonarrService.getV3LanguageProfiles(form.value) this.sonarrService.getV3LanguageProfiles(form.value)
.pipe(catchError((_) => {
this.notificationService.error("Could not load Language Profiles");
return of([]);
}))
.subscribe(x => { .subscribe(x => {
this.langRunning = false;
if (x.length === 0) {
return;
}
this.languageProfiles = x; this.languageProfiles = x;
this.languageProfilesAnime = x; this.languageProfilesAnime = x;
this.langRunning = false;
this.notificationService.success("Successfully retrieved the Language Profiles"); this.notificationService.success("Successfully retrieved the Language Profiles");
}); });
} }
@ -169,11 +191,18 @@ export class SonarrComponent implements OnInit {
public getTags(form: UntypedFormGroup) { public getTags(form: UntypedFormGroup) {
this.tagsRunning = true; this.tagsRunning = true;
this.sonarrService.getTags(form.value).pipe( this.sonarrService.getTags(form.value).pipe(
catchError((_) => {
this.notificationService.error("Could not load Tags");
return of([]);
}),
finalize(() => { finalize(() => {
this.tagsRunning = false; this.tagsRunning = false;
if (this.tags.length === 0) {
return;
}
this.animeTags.unshift({ label: "None", id: -1 }); this.animeTags.unshift({ label: "None", id: -1 });
this.tags.unshift({ label: "None", id: -1 }); this.tags.unshift({ label: "None", id: -1 });
this.notificationService.success("Successfully retrieved the Tags"); this.notificationService.success("Successfully retrieved the Tags")
}), }),
map(result => { map(result => {
this.tags = result; this.tags = result;
@ -204,16 +233,19 @@ export class SonarrComponent implements OnInit {
if (form.controls.defaultQualityProfile) { if (form.controls.defaultQualityProfile) {
if (form.controls.defaultQualityProfile.value === "-1") { if (form.controls.defaultQualityProfile.value === "-1") {
this.notificationService.error("Please check your entered values"); this.notificationService.error("Please check your entered values");
return;
} }
} }
if (form.controls.defaultRootPath) { if (form.controls.defaultRootPath) {
if (form.controls.defaultRootPath.value === "Please Select") { if (form.controls.defaultRootPath.value === "Please Select") {
this.notificationService.error("Please check your entered values"); this.notificationService.error("Please check your entered values");
return;
} }
} }
if (form.controls.languageProfile) { if (form.controls.languageProfile) {
if (form.controls.languageProfile.value === "Please Select") { if (form.controls.languageProfile.value === "Please Select") {
this.notificationService.error("Please check your entered values"); this.notificationService.error("Please check your entered values");
return;
} }
} }
if (form.controls.animeTag.value == -1) { if (form.controls.animeTag.value == -1) {

@ -31,7 +31,7 @@ export class SonarrSettingsState {
} }
@Action(UpdateSettings) @Action(UpdateSettings)
public enable(ctx: StateContext<SonarrState>, { settings }: UpdateSettings): Observable<SonarrState> { public update(ctx: StateContext<SonarrState>, { settings }: UpdateSettings): Observable<SonarrState> {
const state = ctx.getState(); const state = ctx.getState();
return this.settingsService.saveSonarr(settings).pipe( return this.settingsService.saveSonarr(settings).pipe(
tap((_) => ctx.setState({...state, settings})), tap((_) => ctx.setState({...state, settings})),

Loading…
Cancel
Save