-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added APP_INITIALIZER to config and translations from server before a…
…pp is bootstrapped
- Loading branch information
1 parent
529c821
commit 9a2de99
Showing
3 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
client/src/app/services/app-initialization/app-initialization.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { AppInitializationService } from './app-initialization.service'; | ||
|
||
describe('AppInitializationService', () => { | ||
let service: AppInitializationService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(AppInitializationService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
client/src/app/services/app-initialization/app-initialization.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ApiService } from 'src/app/api/services'; | ||
import { LocalStorageService } from '../local-storage/local-storage.service'; | ||
import { Observable, firstValueFrom, shareReplay } from 'rxjs'; | ||
import { FrontendSetupResponse } from 'src/app/api/models'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class AppInitializationService { | ||
private serverConfig?: Observable<FrontendSetupResponse> | ||
|
||
// Note: This service should depend on as few services as possible as it is used early in the bootstrap process | ||
constructor( | ||
private readonly apiService: ApiService, | ||
private readonly localStorageService: LocalStorageService, | ||
) { } | ||
|
||
public async initialize(): Promise<void> { | ||
const userSelectedLanguage = this.getSelectedLanguage() | ||
|
||
this.serverConfig = this.apiService.getFrontendSetup({ | ||
frontend_strings: true, | ||
"accept-language": userSelectedLanguage, | ||
}).pipe( | ||
shareReplay(), | ||
) | ||
|
||
await firstValueFrom(this.serverConfig) | ||
} | ||
|
||
private getSelectedLanguage(): string | undefined { | ||
return this.localStorageService.getString("language") || undefined | ||
} | ||
} |