Skip to content

Commit

Permalink
fix(Application): Retrieve config during APP_INITIALIZATION (#1748)
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokiterashima authored Apr 22, 2024
1 parent 23f8208 commit 4f03631
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ export function initialize(
userService: UserService
): () => Promise<any> {
return (): Promise<any> => {
return userService.retrieveUserPromise().then((user) => {
userService.getUser().subscribe((user) => {
configService.retrieveConfig();
return new Promise((resolve) => {
userService.retrieveUserPromise().then(() => {
return userService.getUser().subscribe(() => {
return configService.retrieveConfig().subscribe((config) => {
resolve(config);
});
});
});
});
};
Expand Down
16 changes: 9 additions & 7 deletions src/app/services/config.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { BehaviorSubject, Observable } from 'rxjs';
import { BehaviorSubject, Observable, tap } from 'rxjs';
import { Config } from '../domain/config';
import { Announcement } from '../domain/announcement';

Expand All @@ -17,14 +17,16 @@ export class ConfigService {
return this.config$;
}

retrieveConfig() {
retrieveConfig(): Observable<Config> {
const headers = new HttpHeaders({ 'Cache-Control': 'no-cache' });
this.http
return this.http
.get<Config>(this.userConfigUrl, { headers: headers })
.subscribe((config) => {
this.config$.next(config);
this.timeDiff = Date.now() - config.currentTime;
});
.pipe(
tap((config) => {
this.config$.next(config);
this.timeDiff = Date.now() - config.currentTime;
})
);
}

getContextPath() {
Expand Down

0 comments on commit 4f03631

Please sign in to comment.