From f28f82f99ef4b3a7bceefcdd8eb7e935da5a50ac Mon Sep 17 00:00:00 2001 From: Jordan Vidrine <30537603+jordanvidrine@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:13:36 -0500 Subject: [PATCH] UX: Multiple fixes to theme card rendering (#29225) * Improvements, refactors, remove dead code --------- Co-authored-by: Martin Brennan --- .../components/admin-config-area-card.gjs | 4 +- .../addon/components/themes-grid-card.gjs | 203 +++++++----------- .../admin/addon/components/themes-grid.gjs | 75 +++---- .../javascripts/admin/addon/models/theme.js | 1 + .../common/components/theme-card.scss | 55 +++-- config/locales/client.en.yml | 2 +- 6 files changed, 161 insertions(+), 179 deletions(-) diff --git a/app/assets/javascripts/admin/addon/components/admin-config-area-card.gjs b/app/assets/javascripts/admin/addon/components/admin-config-area-card.gjs index 63d7687c938..ecb4396f648 100644 --- a/app/assets/javascripts/admin/addon/components/admin-config-area-card.gjs +++ b/app/assets/javascripts/admin/addon/components/admin-config-area-card.gjs @@ -24,7 +24,9 @@ export default class AdminConfigAreaCard extends Component { class="admin-config-area-card__title" >{{this.computedHeading}} {{else}} -

{{yield to="header"}}

+ {{#if (has-block "header")}} +

{{yield to="header"}}

+ {{/if}} {{/if}} {{#if (has-block "headerAction")}}
diff --git a/app/assets/javascripts/admin/addon/components/themes-grid-card.gjs b/app/assets/javascripts/admin/addon/components/themes-grid-card.gjs index 3dfa4ece261..33b50d80cf4 100644 --- a/app/assets/javascripts/admin/addon/components/themes-grid-card.gjs +++ b/app/assets/javascripts/admin/addon/components/themes-grid-card.gjs @@ -1,6 +1,5 @@ import Component from "@glimmer/component"; -import { Input } from "@ember/component"; -import { action, computed } from "@ember/object"; +import { action } from "@ember/object"; import { service } from "@ember/service"; import { htmlSafe } from "@ember/template"; import DButton from "discourse/components/d-button"; @@ -21,54 +20,6 @@ export default class ThemeCard extends Component { @service siteSettings; @service toasts; - // NOTE: These 3 shouldn't need @computed, if we convert - // theme to a pure JS class with @tracked properties we - // won't need to do this. - @computed("args.theme.default") - get setDefaultButtonIcon() { - return this.args.theme.default ? "far-check-square" : "far-square"; - } - - @computed("args.theme.default") - get setDefaultButtonTitle() { - return this.args.theme.default - ? "admin.customize.theme.default_theme" - : "admin.customize.theme.set_default_theme"; - } - - @computed("args.theme.default") - get setDefaultButtonClasses() { - return this.args.theme.default - ? "btn-primary theme-card__button" - : "btn-default theme-card__button"; - } - - @computed( - "args.theme.default", - "args.theme.isBroken", - "args.theme.enabled", - "args.theme.isPendingUpdates" - ) - get themeCardClasses() { - return this.args.theme.isBroken - ? "--broken" - : !this.args.theme.enabled - ? "--disabled" - : this.args.theme.isPendingUpdates - ? "--updates" - : this.args.theme.default - ? "--active" - : ""; - } - - get imageAlt() { - return this.args.theme.name; - } - - get hasScreenshot() { - return this.args.theme.screenshot ? true : false; - } - get themeRouteModels() { return ["themes", this.args.theme.id]; } @@ -92,91 +43,59 @@ export default class ThemeCard extends Component { // Will also need some cleanup when refactoring other theme code. @action async setDefault() { - this.args.theme.set("default", true); - this.args.theme.saveChanges("default").then(() => { - this.args.allThemes.forEach((theme) => { - if (theme.id !== this.args.theme.id) { - theme.set("default", !this.args.theme.get("default")); - } - }); - this.toasts.success({ - data: { - message: I18n.t("admin.customize.theme.set_default_success", { - theme: this.args.theme.name, - }), - }, - duration: 2000, - }); - }); - } + let oldDefaultThemeId; - @action - async handleSubmit(event) { - this.args.theme.set("user_selectable", event.target.checked); - this.args.theme.saveChanges("user_selectable"); + this.args.theme.set("default", true); + this.args.allThemes.forEach((theme) => { + if (theme.id !== this.args.theme.id) { + if (theme.get("default")) { + oldDefaultThemeId = theme.id; + } + + theme.set("default", !this.args.theme.get("default")); + } + }); + + const changesSaved = await this.args.theme.saveChanges("default"); + if (!changesSaved) { + this.args.allThemes + .find((theme) => theme.id === oldDefaultThemeId) + .set("default", true); + this.args.theme.set("default", false); + return; + } + + this.toasts.success({ + data: { + message: I18n.t("admin.customize.theme.set_default_success", { + theme: this.args.theme.name, + }), + }, + duration: 2000, + }); }