Skip to content

Commit

Permalink
DEV: Convert to native class syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaylorhq committed Nov 29, 2024
1 parent 04bb121 commit 71700ba
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions javascripts/discourse/components/category-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import Component from "@ember/component";
import { readOnly } from "@ember/object/computed";
import { classNames } from "@ember-decorators/component";
import { afterRender } from "discourse-common/utils/decorators";

export default Component.extend({
classNames: ["custom-category"],
topicCount: readOnly("c.topic_count"),
@classNames("custom-category")
export default class CategoryWrapper extends Component {
@readOnly("c.topic_count") topicCount;

didInsertElement() {
this._super(...arguments);
super.didInsertElement(...arguments);

if (this.topicCount) {
this.set("hasTopics", true);
this._applyBgColor(this.hexToRgb(this.c.color));
} else {
this.element.style.display = "none";
}
},
}

hexToRgb(hex) {
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
Expand All @@ -32,7 +33,7 @@ export default Component.extend({
b: parseInt(result[3], 16),
}
: null;
},
}

@afterRender
_applyBgColor(color) {
Expand All @@ -42,5 +43,5 @@ export default Component.extend({
this.element.style.backgroundImage = `url(${settings.theme_uploads[bg]})`;
this.element.style.border = `1px solid #${this.c.color}`;
this.element.style.boxShadow = `8px 8px 0 rgba(${color.r},${color.g},${color.b},.25)`;
},
});
}
}

0 comments on commit 71700ba

Please sign in to comment.