move language watcher into current user context
This commit is contained in:
@@ -83,28 +83,6 @@ export class UmbAppElement extends UmbLitElement {
|
||||
}
|
||||
}
|
||||
|
||||
#listenForLanguageChange() {
|
||||
// This will wait for the default language to be loaded before attempting to load the current user language
|
||||
// just in case the user language is not the default language.
|
||||
// We **need** to do this because the default language (typically en-us) holds all the fallback keys for all the other languages.
|
||||
// This way we can ensure that the document language is always loaded first and subsequently registered as the fallback language.
|
||||
this.observe(umbLocalizationRegistry.isDefaultLoaded, (isDefaultLoaded) => {
|
||||
if (!this.#currentUserContext) {
|
||||
throw new Error('[Fatal] CurrentUserContext requested before it was initialized');
|
||||
}
|
||||
|
||||
if (!isDefaultLoaded) return;
|
||||
|
||||
this.observe(
|
||||
this.#currentUserContext.languageIsoCode,
|
||||
(currentLanguageIsoCode) => {
|
||||
umbLocalizationRegistry.loadLanguage(currentLanguageIsoCode);
|
||||
},
|
||||
'languageIsoCode',
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async #setup() {
|
||||
if (this.serverUrl === undefined) throw new Error('No serverUrl provided');
|
||||
|
||||
@@ -196,8 +174,6 @@ export class UmbAppElement extends UmbLitElement {
|
||||
OpenAPI.WITH_CREDENTIALS = true;
|
||||
}
|
||||
|
||||
this.#listenForLanguageChange();
|
||||
|
||||
if (this.#authContext?.isAuthorized()) {
|
||||
this.#authContext?.setLoggedIn(true);
|
||||
} else {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { firstValueFrom } from '@umbraco-cms/backoffice/external/rxjs';
|
||||
import { UserResource } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { UMB_AUTH_CONTEXT } from '@umbraco-cms/backoffice/auth';
|
||||
import { UmbObjectState } from '@umbraco-cms/backoffice/observable-api';
|
||||
import { umbLocalizationRegistry } from '@umbraco-cms/backoffice/localization';
|
||||
|
||||
export class UmbCurrentUserContext extends UmbBaseController {
|
||||
#currentUser = new UmbObjectState<UmbCurrentUser | undefined>(undefined);
|
||||
@@ -23,6 +24,19 @@ export class UmbCurrentUserContext extends UmbBaseController {
|
||||
this.#observeIsLoggedIn();
|
||||
});
|
||||
|
||||
// TODO: revisit this. It can probably be simplified
|
||||
this.observe(umbLocalizationRegistry.isDefaultLoaded, (isDefaultLoaded) => {
|
||||
if (!isDefaultLoaded) return;
|
||||
|
||||
this.observe(
|
||||
this.languageIsoCode,
|
||||
(currentLanguageIsoCode) => {
|
||||
umbLocalizationRegistry.loadLanguage(currentLanguageIsoCode);
|
||||
},
|
||||
'umbCurrentUserLanguageIsoCode',
|
||||
);
|
||||
});
|
||||
|
||||
this.provideContext(UMB_CURRENT_USER_CONTEXT, this);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user