Skip to content

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

DEV: migrates user-stat to gjs (#27867)

Joffrey JAFFEUX0614279b9da8
diff --git a/app/assets/javascripts/discourse/app/components/user-stat.gjs b/app/assets/javascripts/discourse/app/components/user-stat.gjs
new file mode 100644
index 00000000000..290e7a61a88
--- /dev/null
+++ b/app/assets/javascripts/discourse/app/components/user-stat.gjs
@@ -0,0 +1,38 @@
+import Component from "@glimmer/component";
+import { htmlSafe } from "@ember/template";
+import formatDuration from "discourse/helpers/format-duration";
+import number from "discourse/helpers/number";
+import icon from "discourse-common/helpers/d-icon";
+import i18n from "discourse-common/helpers/i18n";
+
+export default class UserStat extends Component {
+ get type() {
+ return this.args.type ?? "number";
+ }
+
+ get isNumber() {
+ return this.type === "number";
+ }
+
+ get isDuration() {
+ return this.type === "duration";
+ }
+
+ <template>
+ <div class="user-stat">
+ <span class="value" title={{@rawTitle}}>
+ {{#if this.isNumber}}
+ {{number @value}}
+ {{else if this.isDuration}}
+ {{formatDuration @value}}
+ {{else}}
+ {{@value}}
+ {{/if}}
+ </span>
+ <span class="label">
+ {{#if @icon}}{{icon @icon}}{{/if}}
+ {{htmlSafe (i18n @label count=@value)}}
+ </span>
+ </div>
+ </template>
+}
diff --git a/app/assets/javascripts/discourse/app/components/user-stat.hbs b/app/assets/javascripts/discourse/app/components/user-stat.hbs
deleted file mode 100644
index 654ac59dee7..00000000000
--- a/app/assets/javascripts/discourse/app/components/user-stat.hbs
+++ /dev/null
@@ -1,13 +0,0 @@
-<span class="value" title={{this.rawTitle}}>
- {{#if this.isNumber}}
- {{number @value}}
- {{else if this.isDuration}}
- {{format-duration @value}}
- {{else}}
- {{@value}}
- {{/if}}
-</span>
-<span class="label">
- {{#if @icon}}{{d-icon @icon}}{{/if}}
- {{html-safe (i18n @label count=@value)}}
-</span>
\ No newline at end of file
diff --git a/app/assets/javascripts/discourse/app/components/user-stat.js b/app/assets/javascripts/discourse/app/components/user-stat.js
deleted file mode 100644
index bc33c00a5d2..00000000000
--- a/app/assets/javascripts/discourse/app/components/user-stat.js
+++ /dev/null
@@ -1,8 +0,0 @@
-import Component from "@ember/component";
-import { equal } from "@ember/object/computed";
-export default Component.extend({
- classNames: ["user-stat"],
- type: "number",
- isNumber: equal("type", "number"),
- isDuration: equal("type", "duration"),
-});