DEV: migrates user-badge to gjs (#27866)

Co-authored-by: Jarek Radosz <jarek@cvx.dev>
This commit is contained in:
Joffrey JAFFEUX 2024-07-11 11:55:42 +02:00 committed by GitHub
parent b024e32e74
commit 48f36e52a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 26 deletions

View File

@ -0,0 +1,25 @@
import Component from "@glimmer/component";
import BadgeButton from "discourse/components/badge-button";
export default class UserBadge extends Component {
get showGrantCount() {
return this.args.count > 1;
}
get badgeUrl() {
// NOTE: I tried using a link-to helper here but the queryParams mean it fails
let username = this.args.user?.username_lower;
username = username ? `?username=${username}` : "";
return this.args.badge.url + username;
}
<template>
<a class="user-card-badge-link" href={{this.badgeUrl}}>
<BadgeButton @badge={{@badge}}>
{{#if this.showGrantCount}}
<span class="count">&nbsp;(&times;{{@count}})</span>
{{/if}}
</BadgeButton>
</a>
</template>
}

View File

@ -1,7 +0,0 @@
<a class="user-card-badge-link" href={{this.badgeUrl}}>
<BadgeButton @badge={{@badge}}>
{{#if this.showGrantCount}}
<span class="count">&nbsp;(&times;{{@count}})</span>
{{/if}}
</BadgeButton>
</a>

View File

@ -1,19 +0,0 @@
import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators";
export default Component.extend({
tagName: "",
@discourseComputed("count")
showGrantCount(count) {
return count && count > 1;
},
@discourseComputed("badge", "user")
badgeUrl() {
// NOTE: I tried using a link-to helper here but the queryParams mean it fails
let username = this.get("user.username_lower") || "";
username = username !== "" ? "?username=" + username : "";
return this.get("badge.url") + username;
},
});