Skip to content

A platform for community discussion. Free, open, simple.

FIX: Allow themes index to resort when adding new themes (#34314)

Martin Brennan37b86e139f23
diff --git a/app/assets/javascripts/admin/addon/components/themes-grid.gjs b/app/assets/javascripts/admin/addon/components/themes-grid.gjs
index 2d2896f7534..5085f85f48a 100644
--- a/app/assets/javascripts/admin/addon/components/themes-grid.gjs
+++ b/app/assets/javascripts/admin/addon/components/themes-grid.gjs
@@ -1,4 +1,5 @@
import Component from "@glimmer/component";
+import { cached } from "@glimmer/tracking";
import { service } from "@ember/service";
import PluginOutlet from "discourse/components/plugin-outlet";
import lazyHash from "discourse/helpers/lazy-hash";
@@ -7,30 +8,15 @@ import AdminConfigAreaCard from "admin/components/admin-config-area-card";
import AdminFilterControls from "admin/components/admin-filter-controls";
import ThemesGridCard from "./themes-grid-card";
-// NOTE (martin): Much of the JS code in this component is placeholder code. Much
-// of the existing theme logic in /admin/customize/themes has old patterns
-// and technical debt, so anything copied from there to here is subject
-// to change as we improve this incrementally.
-
const FILTER_MINIMUM = 8;
export default class ThemesGrid extends Component {
@service modal;
@service router;
- sortedThemes;
-
- constructor() {
- super(...arguments);
-
- // Show default theme at the top of the list on page load,
- // but don't move it around dynamically if the admin changes the default.
- //
- // TODO (martin) Figure out how to make it so we can sort default to the
- // top but also allow the list of themes to change if an additional theme is
- // installed. Basically don't want .get("default") to affect the sort after
- // the first time, but if the whole array changes this needs to be recalculated.
- this.sortedThemes = this.args.themes.sort((a, b) => {
+ @cached
+ get sortedThemes() {
+ return this.args.themes.sort((a, b) => {
if (a.get("default")) {
return -1;
} else if (b.get("default")) {
diff --git a/app/assets/javascripts/admin/addon/controllers/admin-customize-colors.js b/app/assets/javascripts/admin/addon/controllers/admin-customize-colors.js
index b763a664e7d..87944a2e76c 100644
--- a/app/assets/javascripts/admin/addon/controllers/admin-customize-colors.js
+++ b/app/assets/javascripts/admin/addon/controllers/admin-customize-colors.js
@@ -32,7 +32,7 @@ export default class AdminCustomizeColorsController extends Controller {
_initialUserDarkColorSchemeId = undefined;
_initialDefaultThemeLightColorSchemeId = null;
_initialDefaultThemeDarkColorSchemeId = null;
- _sortedOnce = false;
+ _sortPerformed = false;
canPreviewColorScheme(mode) {
const usingDefaultTheme = currentThemeId() === this.defaultTheme?.id;
@@ -80,7 +80,7 @@ export default class AdminCustomizeColorsController extends Controller {
get sortedColorSchemes() {
// only sort initially, this avoids position jumps when state changes on interaction
- if (!this._sortedOnce && this.model?.length > 0) {
+ if (!this._sortPerformed && this.model?.length > 0) {
this._doInitialSort();
}
@@ -158,11 +158,11 @@ export default class AdminCustomizeColorsController extends Controller {
});
this._initialSortedSchemes = schemes;
- this._sortedOnce = true;
+ this._sortPerformed = true;
}
_resetSortedSchemes() {
- this._sortedOnce = false;
+ this._sortPerformed = false;
this._initialSortedSchemes = [];
}