update code to get the current user from new context
This commit is contained in:
@@ -2,7 +2,7 @@ import { UmbEntityData } from './entity.data.js';
|
||||
import { umbUserGroupData } from './user-group.data.js';
|
||||
import { arrayFilter, stringFilter, queryFilter } from './utils.js';
|
||||
import { UmbId } from '@umbraco-cms/backoffice/id';
|
||||
import { UmbCurrentUser } from '@umbraco-cms/backoffice/auth';
|
||||
import { UmbCurrentUser } from '@umbraco-cms/backoffice/current-user';
|
||||
import {
|
||||
CreateUserRequestModel,
|
||||
CreateUserResponseModel,
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
type RawEditorOptions,
|
||||
renderEditor,
|
||||
} from '@umbraco-cms/backoffice/external/tinymce';
|
||||
import { UMB_AUTH_CONTEXT, UmbLoggedInUser } from '@umbraco-cms/backoffice/auth';
|
||||
import { UMB_CURRENT_USER_CONTEXT, UmbCurrentUser } from '@umbraco-cms/backoffice/current-user';
|
||||
import { TinyMcePluginArguments, UmbTinyMcePluginBase } from '@umbraco-cms/backoffice/components';
|
||||
import { ClassConstructor, hasDefaultExport, loadExtension } from '@umbraco-cms/backoffice/extension-api';
|
||||
import { ManifestTinyMcePlugin, umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
|
||||
@@ -39,8 +39,8 @@ export class UmbInputTinyMceElement extends FormControlMixin(UmbLitElement) {
|
||||
private _tinyConfig: RawEditorOptions = {};
|
||||
|
||||
#mediaHelper = new UmbMediaHelper();
|
||||
#currentUser?: UmbLoggedInUser;
|
||||
#auth?: typeof UMB_AUTH_CONTEXT.TYPE;
|
||||
#currentUser?: UmbCurrentUser;
|
||||
#currentUserContext?: typeof UMB_CURRENT_USER_CONTEXT.TYPE;
|
||||
#plugins: Array<new (args: TinyMcePluginArguments) => UmbTinyMcePluginBase> = [];
|
||||
#editorRef?: Editor | null = null;
|
||||
#stylesheetRepository?: UmbStylesheetRepository;
|
||||
@@ -71,9 +71,9 @@ export class UmbInputTinyMceElement extends FormControlMixin(UmbLitElement) {
|
||||
}
|
||||
|
||||
async #observeCurrentUser() {
|
||||
if (!this.#auth) return;
|
||||
if (!this.#currentUserContext) return;
|
||||
|
||||
this.observe(this.#auth.currentUser, (currentUser) => (this.#currentUser = currentUser));
|
||||
this.observe(this.#currentUserContext.currentUser, (currentUser) => (this.#currentUser = currentUser));
|
||||
}
|
||||
|
||||
protected async firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): Promise<void> {
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
UmbModalManagerContext,
|
||||
UMB_MODAL_MANAGER_CONTEXT_TOKEN,
|
||||
} from '@umbraco-cms/backoffice/modal';
|
||||
import { UMB_AUTH_CONTEXT, UmbCurrentUser } from '@umbraco-cms/backoffice/auth';
|
||||
import { UMB_CURRENT_USER_CONTEXT, UmbCurrentUser } from '@umbraco-cms/backoffice/current-user';
|
||||
|
||||
interface MediaPickerTargetData {
|
||||
altText?: string;
|
||||
@@ -28,7 +28,7 @@ export default class UmbTinyMceMediaPickerPlugin extends UmbTinyMcePluginBase {
|
||||
#mediaHelper: UmbMediaHelper;
|
||||
#currentUser?: UmbCurrentUser;
|
||||
#modalContext?: UmbModalManagerContext;
|
||||
#auth?: typeof UMB_AUTH_CONTEXT.TYPE;
|
||||
#currentUserContext?: typeof UMB_CURRENT_USER_CONTEXT.TYPE;
|
||||
|
||||
constructor(args: TinyMcePluginArguments) {
|
||||
super(args);
|
||||
@@ -41,8 +41,8 @@ export default class UmbTinyMceMediaPickerPlugin extends UmbTinyMcePluginBase {
|
||||
|
||||
// TODO => this breaks tests. disabling for now
|
||||
// will ignore user media start nodes
|
||||
// this.host.consumeContext(UMB_AUTH, (instance) => {
|
||||
// this.#auth = instance;
|
||||
// this.host.consumeContext(UMB_CURRENT_USER_CONTEXT, (instance) => {
|
||||
// this.#currentUserContext = instance;
|
||||
// this.#observeCurrentUser();
|
||||
// });
|
||||
|
||||
@@ -55,9 +55,9 @@ export default class UmbTinyMceMediaPickerPlugin extends UmbTinyMcePluginBase {
|
||||
}
|
||||
|
||||
async #observeCurrentUser() {
|
||||
if (!this.#auth) return;
|
||||
if (!this.#currentUserContext) return;
|
||||
|
||||
this.host.observe(this.#auth.currentUser, (currentUser) => (this.#currentUser = currentUser));
|
||||
this.host.observe(this.#currentUserContext.currentUser, (currentUser) => (this.#currentUser = currentUser));
|
||||
}
|
||||
|
||||
async #onAction() {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { UmbLitElement } from '@umbraco-cms/internal/lit-element';
|
||||
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
|
||||
import { UUISelectElement } from '@umbraco-cms/backoffice/external/uui';
|
||||
import { UserResponseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { UMB_AUTH_CONTEXT, UmbLoggedInUser } from '@umbraco-cms/backoffice/auth';
|
||||
import { UMB_AUTH_CONTEXT, UmbCurrentUser } from '@umbraco-cms/backoffice/auth';
|
||||
import { firstValueFrom } from '@umbraco-cms/backoffice/external/rxjs';
|
||||
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
@@ -14,7 +14,7 @@ export class UmbUserWorkspaceProfileSettingsElement extends UmbLitElement {
|
||||
private _user?: UserResponseModel;
|
||||
|
||||
@state()
|
||||
private _currentUser?: UmbLoggedInUser;
|
||||
private _currentUser?: UmbCurrentUser;
|
||||
|
||||
@state()
|
||||
private languages: Array<{ name: string; value: string; selected: boolean }> = [];
|
||||
@@ -46,41 +46,45 @@ export class UmbUserWorkspaceProfileSettingsElement extends UmbLitElement {
|
||||
|
||||
#observeCurrentUser() {
|
||||
if (!this.#authContext) return;
|
||||
this.observe(this.#authContext.currentUser, async (currentUser) => {
|
||||
this._currentUser = currentUser;
|
||||
this.observe(
|
||||
this.#authContext.currentUser,
|
||||
async (currentUser) => {
|
||||
this._currentUser = currentUser;
|
||||
|
||||
if (!currentUser) {
|
||||
return;
|
||||
}
|
||||
if (!currentUser) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Find all translations and make a unique list of iso codes
|
||||
const translations = await firstValueFrom(umbExtensionsRegistry.extensionsOfType('localization'));
|
||||
// Find all translations and make a unique list of iso codes
|
||||
const translations = await firstValueFrom(umbExtensionsRegistry.extensionsOfType('localization'));
|
||||
|
||||
this.languages = translations
|
||||
.filter((isoCode) => isoCode !== undefined)
|
||||
.map((translation) => ({
|
||||
value: translation.meta.culture.toLowerCase(),
|
||||
name: translation.name,
|
||||
selected: false,
|
||||
}));
|
||||
this.languages = translations
|
||||
.filter((isoCode) => isoCode !== undefined)
|
||||
.map((translation) => ({
|
||||
value: translation.meta.culture.toLowerCase(),
|
||||
name: translation.name,
|
||||
selected: false,
|
||||
}));
|
||||
|
||||
const currentUserLanguageCode = currentUser.languageIsoCode?.toLowerCase();
|
||||
const currentUserLanguageCode = currentUser.languageIsoCode?.toLowerCase();
|
||||
|
||||
// Set the current user's language as selected
|
||||
const currentUserLanguage = this.languages.find((language) => language.value === currentUserLanguageCode);
|
||||
// Set the current user's language as selected
|
||||
const currentUserLanguage = this.languages.find((language) => language.value === currentUserLanguageCode);
|
||||
|
||||
if (currentUserLanguage) {
|
||||
currentUserLanguage.selected = true;
|
||||
} else {
|
||||
// If users language code did not fit any of the options. We will create an option that fits, named unknown.
|
||||
// In this way the user can keep their choice though a given language was not present at this time.
|
||||
this.languages.push({
|
||||
value: currentUserLanguageCode ?? 'en-us',
|
||||
name: currentUserLanguageCode ? `${currentUserLanguageCode} (unknown)` : 'Unknown',
|
||||
selected: true,
|
||||
});
|
||||
}
|
||||
}, 'umbUserObserver');
|
||||
if (currentUserLanguage) {
|
||||
currentUserLanguage.selected = true;
|
||||
} else {
|
||||
// If users language code did not fit any of the options. We will create an option that fits, named unknown.
|
||||
// In this way the user can keep their choice though a given language was not present at this time.
|
||||
this.languages.push({
|
||||
value: currentUserLanguageCode ?? 'en-us',
|
||||
name: currentUserLanguageCode ? `${currentUserLanguageCode} (unknown)` : 'Unknown',
|
||||
selected: true,
|
||||
});
|
||||
}
|
||||
},
|
||||
'umbUserObserver',
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
Reference in New Issue
Block a user