Files
grimmory/frontend/src/app/shared/service/settings-helper.service.ts
T
James Cox 874b013f75 refactor(frontend): rename booklore-ui to frontend
- Frontend path:
  - rename the tracked Angular app tree from `booklore-ui/` to `frontend/`
  - preserve file contents during the move so this commit stays focused on the path change itself
- Frontend docs:
  - update the moved frontend README and contribution guide where they refer to the renamed folder
  - keep those edits limited to path references introduced by the directory rename
2026-04-22 17:26:39 -04:00

51 lines
1.5 KiB
TypeScript

import {Injectable, inject} from '@angular/core';
import {AppSettingsService} from './app-settings.service';
import {MessageService} from 'primeng/api';
import {TranslocoService} from '@jsverse/transloco';
import {Observable} from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class SettingsHelperService {
private readonly appSettingsService = inject(AppSettingsService);
private readonly messageService = inject(MessageService);
private readonly t = inject(TranslocoService);
saveSetting(key: string, value: unknown): Observable<void> {
const observable = this.appSettingsService.saveSettings([{key, newValue: value}]);
observable.subscribe({
next: () => this.showSuccessMessage(),
error: (error) => {
console.error('Failed to save setting:', error);
this.showErrorMessage();
}
});
return observable;
}
private showSuccessMessage(): void {
this.messageService.add({
severity: 'success',
summary: this.t.translate('shared.settingsHelper.settingsSavedSummary'),
detail: this.t.translate('shared.settingsHelper.settingsSavedDetail')
});
}
private showErrorMessage(): void {
this.messageService.add({
severity: 'error',
summary: this.t.translate('common.error'),
detail: this.t.translate('shared.settingsHelper.saveErrorDetail')
});
}
showMessage(severity: 'success' | 'error', summary: string, detail: string): void {
this.messageService.add({severity, summary, detail});
}
}