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:
brios
2026-04-22 17:27:11 -04:00
committed by Zach Yale
parent 85e8d235b6
commit 7abac02b0c
25 changed files with 218 additions and 180 deletions
@@ -15,7 +15,6 @@ import { AuthService } from '../../service/auth.service';
import { UserService } from '../../../features/settings/user-management/user.service';
import { Popover } from 'primeng/popover';
import { MetadataProgressService } from '../../service/metadata-progress.service';
import { MetadataBatchProgressNotification } from '../../model/metadata-batch-progress.model';
import { BookdropFileService } from '../../../features/bookdrop/service/bookdrop-file.service';
import { DialogLauncherService } from '../../services/dialog-launcher.service';
@@ -69,8 +68,8 @@ export class AppTopBarComponent implements OnDestroy {
hasAnyTasks = false;
hasPendingBookdropFiles = false;
private eventTimer: number | undefined;
private readonly destroyRef = inject(DestroyRef);
private eventTimer: number | undefined;
private latestTasks: Record<string, MetadataBatchProgressNotification> = {};
private latestHasPendingFiles = false;
@@ -85,6 +84,8 @@ export class AppTopBarComponent implements OnDestroy {
this.subscribeToMetadataProgress();
this.subscribeToNotifications();
this.destroyRef.onDestroy(() => clearTimeout(this.eventTimer));
this.metadataProgressService.activeTasks$
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((tasks) => {
@@ -158,7 +159,7 @@ export class AppTopBarComponent implements OnDestroy {
switchLanguage(lang: string) {
if (lang === this.activeLang) return;
this.translocoService.load(lang).subscribe(() => {
this.translocoService.load(lang).pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => {
this.translocoService.setActiveLang(lang);
localStorage.setItem(LANG_STORAGE_KEY, lang);
this.activeLang = lang;