refactor(settings): replace unsubscribe logic with takeUntilDestroyed for better resource management (#443)
* refactor(settings): replace unsubscribe logic with takeUntilDestroyed for better resource management * refactor(settings): streamline saveSettings method and improve error handling * fix(settings): improve error handling in saveSetting method * refactor(settings): update tab structure * refactor(settings): implement OnDestroy interface and clean up unused destroyRef instances
This commit is contained in:
+9
-3
@@ -1,4 +1,5 @@
|
||||
import {Component, effect, inject, OnInit} from '@angular/core';
|
||||
import {Component, DestroyRef, effect, inject, OnInit} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {MenuItem, MessageService} from 'primeng/api';
|
||||
import {Button} from 'primeng/button';
|
||||
@@ -46,6 +47,7 @@ export class GlobalPreferencesComponent implements OnInit {
|
||||
private bookMetadataManageService = inject(BookMetadataManageService);
|
||||
private messageService = inject(MessageService);
|
||||
private t = inject(TranslocoService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
private readonly syncSettingsEffect = effect(() => {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
@@ -103,7 +105,9 @@ export class GlobalPreferencesComponent implements OnInit {
|
||||
}
|
||||
|
||||
regenerateCovers(missingOnly = false): void {
|
||||
this.bookMetadataManageService.regenerateCovers(missingOnly).subscribe({
|
||||
this.bookMetadataManageService.regenerateCovers(missingOnly).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () =>
|
||||
this.showMessage('success', this.t.translate('settingsApp.covers.regenerateStarted'), this.t.translate('settingsApp.covers.regenerateStartedDetail')),
|
||||
error: () =>
|
||||
@@ -112,7 +116,9 @@ export class GlobalPreferencesComponent implements OnInit {
|
||||
}
|
||||
|
||||
private saveSetting(key: string, value: unknown): void {
|
||||
this.appSettingsService.saveSettings([{key, newValue: value}]).subscribe({
|
||||
this.appSettingsService.saveSettings([{key, newValue: value}]).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () =>
|
||||
this.showMessage('success', this.t.translate('settingsApp.settingsSaved'), this.t.translate('settingsApp.settingsSavedDetail')),
|
||||
error: () =>
|
||||
|
||||
+9
-3
@@ -1,4 +1,5 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {Component, DestroyRef, inject, OnInit} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {MetadataMatchWeightsService} from '../../../../shared/service/metadata-match-weights.service';
|
||||
@@ -39,6 +40,7 @@ export class MetadataMatchWeightsComponent implements OnInit {
|
||||
private messageService = inject(MessageService);
|
||||
private fb = inject(FormBuilder);
|
||||
private t = inject(TranslocoService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.form = this.fb.group({
|
||||
@@ -95,7 +97,9 @@ export class MetadataMatchWeightsComponent implements OnInit {
|
||||
}
|
||||
];
|
||||
|
||||
this.appSettingsService.saveSettings(payload).subscribe({
|
||||
this.appSettingsService.saveSettings(payload).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
@@ -117,7 +121,9 @@ export class MetadataMatchWeightsComponent implements OnInit {
|
||||
|
||||
recalculate(): void {
|
||||
this.isRecalculating = true;
|
||||
this.weightsService.recalculateAll().subscribe({
|
||||
this.weightsService.recalculateAll().pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
|
||||
+6
-2
@@ -1,4 +1,5 @@
|
||||
import {Component, effect, inject} from '@angular/core';
|
||||
import {Component, DestroyRef, effect, inject} from '@angular/core';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {TableModule} from 'primeng/table';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
@@ -100,6 +101,7 @@ export class MetadataProviderSettingsComponent {
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private messageService = inject(MessageService);
|
||||
private t = inject(TranslocoService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
private readonly syncSettingsEffect = effect(() => {
|
||||
const settings = this.appSettingsService.appSettings();
|
||||
@@ -174,7 +176,9 @@ export class MetadataProviderSettingsComponent {
|
||||
}
|
||||
];
|
||||
|
||||
this.appSettingsService.saveSettings(payload).subscribe({
|
||||
this.appSettingsService.saveSettings(payload).pipe(
|
||||
takeUntilDestroyed(this.destroyRef)
|
||||
).subscribe({
|
||||
next: () =>
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
|
||||
Reference in New Issue
Block a user