diff --git a/frontend/src/app/routes/settings/syspref/syspref-option/settings-syspref-option.component.ts b/frontend/src/app/routes/settings/syspref/syspref-option/settings-syspref-option.component.ts
index 83e412f..dad5c8a 100644
--- a/frontend/src/app/routes/settings/syspref/syspref-option/settings-syspref-option.component.ts
+++ b/frontend/src/app/routes/settings/syspref/syspref-option/settings-syspref-option.component.ts
@@ -1,11 +1,14 @@
import { Component, Input, OnInit } from '@angular/core';
import { AutoUnsubscribe } from 'ngx-auto-unsubscribe-decorator';
import { SysPreferenceBaseResponse } from 'picsur-shared/dist/dto/api/pref.dto';
-import { SysPreference, SysPrefValueType } from 'picsur-shared/dist/dto/syspreferences.dto';
+import {
+ SysPreference,
+ SysPrefValueType
+} from 'picsur-shared/dist/dto/syspreferences.dto';
import { HasFailed } from 'picsur-shared/dist/types';
import { Subject, throttleTime } from 'rxjs';
import { SysPreferenceFriendlyNames } from 'src/app/i18n/syspref.i18n';
-import { SnackBarType } from "src/app/models/dto/snack-bar-type.dto";
+import { SnackBarType } from 'src/app/models/dto/snack-bar-type.dto';
import { SysprefService } from 'src/app/services/api/syspref.service';
import { UtilService } from 'src/app/util/util.service';
@@ -29,7 +32,10 @@ export class SettingsSysprefOptionComponent implements OnInit {
}
get name(): string {
- return SysPreferenceFriendlyNames[this.pref.key as SysPreference] ?? this.pref.key;
+ return (
+ SysPreferenceFriendlyNames[this.pref.key as SysPreference] ??
+ this.pref.key
+ );
}
get valString(): string {
@@ -65,26 +71,28 @@ export class SettingsSysprefOptionComponent implements OnInit {
this.update((e.target as HTMLInputElement).valueAsNumber);
}
+ private async updatePreference(value: SysPrefValueType) {
+ const result = await this.sysprefService.setPreference(
+ this.pref.key,
+ value
+ );
+ if (!HasFailed(result)) {
+ this.utilService.showSnackBar(
+ `Updated ${this.name}`,
+ SnackBarType.Success
+ );
+ } else {
+ this.utilService.showSnackBar(
+ `Failed to update ${this.name}`,
+ SnackBarType.Error
+ );
+ }
+ }
+
@AutoUnsubscribe()
subscribeUpdate() {
return this.updateSubject
.pipe(throttleTime(300, undefined, { leading: true, trailing: true }))
- .subscribe(async (value) => {
- const result = await this.sysprefService.setPreference(
- this.pref.key,
- value
- );
- if (!HasFailed(result)) {
- this.utilService.showSnackBar(
- `Updated ${this.name}`,
- SnackBarType.Success
- );
- } else {
- this.utilService.showSnackBar(
- `Failed to update ${this.name}`,
- SnackBarType.Error
- );
- }
- });
+ .subscribe(this.updatePreference.bind(this));
}
}