1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-12 11:15:22 +02:00

improving settings fetching

This commit is contained in:
Patrik J. Braun 2019-12-10 15:30:29 +01:00
parent b6b8a9e203
commit 8029793ffb

View File

@ -9,6 +9,7 @@ import {IPrivateConfig, ServerConfig} from '../../../../common/config/private/IP
@Injectable() @Injectable()
export class SettingsService { export class SettingsService {
public settings: BehaviorSubject<IPrivateConfig>; public settings: BehaviorSubject<IPrivateConfig>;
private fetchingSettings = false;
constructor(private _networkService: NetworkService) { constructor(private _networkService: NetworkService) {
this.settings = new BehaviorSubject<IPrivateConfig>({ this.settings = new BehaviorSubject<IPrivateConfig>({
@ -127,7 +128,16 @@ export class SettingsService {
} }
public async getSettings(): Promise<void> { public async getSettings(): Promise<void> {
this.settings.next(await this._networkService.getJson<Promise<IPrivateConfig>>('/settings')); if (this.fetchingSettings === true) {
return;
}
this.fetchingSettings = true;
try {
this.settings.next(await this._networkService.getJson<Promise<IPrivateConfig>>('/settings'));
} catch (e) {
console.error(e);
}
this.fetchingSettings = false;
} }