From 574cb28b0e0ad659a6c08b81b428c69218931bd5 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Tue, 28 Sep 2021 14:09:15 -0400 Subject: [PATCH] DEV: Sort styleguide icons alphabetically and fix render on refresh (#14463) Co-authored-by: Jarek Radosz --- .../discourse/components/styleguide-icons.js.es6 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/styleguide/assets/javascripts/discourse/components/styleguide-icons.js.es6 b/plugins/styleguide/assets/javascripts/discourse/components/styleguide-icons.js.es6 index ab2be7eb7d8..716e3d3b14b 100644 --- a/plugins/styleguide/assets/javascripts/discourse/components/styleguide-icons.js.es6 +++ b/plugins/styleguide/assets/javascripts/discourse/components/styleguide-icons.js.es6 @@ -1,4 +1,5 @@ import { afterRender } from "discourse-common/utils/decorators"; +import { later } from "@ember/runloop"; export default Ember.Component.extend({ tagName: "section", @@ -13,8 +14,12 @@ export default Ember.Component.extend({ @afterRender setIconIds() { let symbols = document.querySelectorAll("#svg-sprites symbol"); - let ids = Array.from(symbols).mapBy("id"); - - this.set("iconIds", ids); + if (symbols.length > 0) { + let ids = Array.from(symbols).mapBy("id"); + this.set("iconIds", ids.sort()); + } else { + // Let's try again a short time later if there are no svgs loaded yet + later(this, this.setIconIds, 1500); + } }, });