DEV: Resolve avatar-selector `computed-property.override` deprecation (#20616)

This commit is contained in:
David Taylor 2023-03-09 18:05:46 +00:00 committed by GitHub
parent f144c64e13
commit 4f9afabf87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 15 deletions

View File

@ -7,6 +7,8 @@ import discourseComputed from "discourse-common/utils/decorators";
import { popupAjaxError } from "discourse/lib/ajax-error"; import { popupAjaxError } from "discourse/lib/ajax-error";
import { setting } from "discourse/lib/computed"; import { setting } from "discourse/lib/computed";
import { isTesting } from "discourse-common/config/environment"; import { isTesting } from "discourse-common/config/environment";
import { dependentKeyCompat } from "@ember/object/compat";
import { tracked } from "@glimmer/tracking";
export default Controller.extend(ModalFunctionality, { export default Controller.extend(ModalFunctionality, {
gravatarName: setting("gravatar_name"), gravatarName: setting("gravatar_name"),
@ -56,23 +58,30 @@ export default Controller.extend(ModalFunctionality, {
} }
}, },
@discourseComputed( @tracked _selected: null,
"user.use_logo_small_as_avatar",
"user.avatar_template", @dependentKeyCompat
"user.system_avatar_template", get selected() {
"user.gravatar_avatar_template" return this._selected ?? this.defaultSelection;
) },
selected(
useLogo, @action
avatarTemplate, onSelectedChanged(value) {
systemAvatarTemplate, this._selected = value;
gravatarAvatarTemplate },
) {
if (useLogo) { get defaultSelection() {
if (this.get("user.use_logo_small_as_avatar")) {
return "logo"; return "logo";
} else if (avatarTemplate === systemAvatarTemplate) { } else if (
this.get("user.avatar_template") ===
this.get("user.system_avatar_template")
) {
return "system"; return "system";
} else if (avatarTemplate === gravatarAvatarTemplate) { } else if (
this.get("user.avatar_template") ===
this.get("user.gravatar_avatar_template")
) {
return "gravatar"; return "gravatar";
} else { } else {
return "custom"; return "custom";

View File

@ -23,6 +23,7 @@
@name="logo" @name="logo"
@value="logo" @value="logo"
@selection={{this.selected}} @selection={{this.selected}}
@onChange={{this.onSelectedChanged}}
/> />
<label class="radio" for="logo-small">{{bound-avatar-template <label class="radio" for="logo-small">{{bound-avatar-template
this.siteSettings.site_logo_small_url this.siteSettings.site_logo_small_url
@ -37,6 +38,7 @@
@name="avatar" @name="avatar"
@value="system" @value="system"
@selection={{this.selected}} @selection={{this.selected}}
@onChange={{this.onSelectedChanged}}
/> />
<label class="radio" for="system-avatar">{{bound-avatar-template <label class="radio" for="system-avatar">{{bound-avatar-template
this.user.system_avatar_template this.user.system_avatar_template
@ -51,6 +53,7 @@
@name="avatar" @name="avatar"
@value="gravatar" @value="gravatar"
@selection={{this.selected}} @selection={{this.selected}}
@onChange={{this.onSelectedChanged}}
/> />
<label class="radio" for="gravatar">{{bound-avatar-template <label class="radio" for="gravatar">{{bound-avatar-template
this.user.gravatar_avatar_template this.user.gravatar_avatar_template
@ -90,6 +93,7 @@
@name="avatar" @name="avatar"
@value="custom" @value="custom"
@selection={{this.selected}} @selection={{this.selected}}
@onChange={{this.onSelectedChanged}}
/> />
<label class="radio" for="uploaded-avatar"> <label class="radio" for="uploaded-avatar">
{{#if this.user.custom_avatar_template}} {{#if this.user.custom_avatar_template}}