Skip to content

Commit

Permalink
Fixes v17development#9: Badges visible on UserCard
Browse files Browse the repository at this point in the history
  • Loading branch information
datlechin committed Jun 17, 2022
1 parent 7a4cb48 commit fcd2acd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
27 changes: 27 additions & 0 deletions js/src/forum/components/addBadgeListUserCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { extend } from 'flarum/common/extend';
import UserCard from 'flarum/forum/components/UserCard';
import UserBadge from '../../common/components/UserBadge';
import BadgeModal from './BadgeModal';

export default function addBadgeListUserCard() {
extend(UserCard.prototype, 'infoItems', function (items) {
const userBadges = this.attrs.user.userBadges();

if (userBadges.length < 1) return;

items.add(
'badges',
userBadges.map((userBadge) => (
<UserBadge
badge={userBadge.badge()}
onclick={() =>
app.modal.show(BadgeModal, {
badge: userBadge.badge(),
userBadgeData: userBadge,
})
}
/>
))
);
});
}
2 changes: 2 additions & 0 deletions js/src/forum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import addSidebarNav from './addSidebarNav';
import UserBadgeListState from './states/UserBadgeListState';
import BadgeReceivedNotification from './notification/BadgeReceivedNotification';
import NotificationGrid from 'flarum/forum/components/NotificationGrid';
import addBadgeListUserCard from './components/addBadgeListUserCard';

app.initializers.add('v17development-flarum-badges', (app) => {
app.store.models.badges = Badge;
Expand Down Expand Up @@ -105,4 +106,5 @@ app.initializers.add('v17development-flarum-badges', (app) => {
);
}
});
addBadgeListUserCard();
});
1 change: 1 addition & 0 deletions less/forum.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
@import "./forum/BadgePage.less";
@import "./forum/BadgeOverviewPage.less";
@import "./forum/BadgeUserList.less";
@import "forum/BadgeUserCard";
14 changes: 14 additions & 0 deletions less/forum/BadgeUserCard.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.UserCard-info {
.item-badges {
display: block!important;
margin-top: 15px;

.UserBadge {
color: #fff;

&:hover {
border-color: #fff;
}
}
}
}

0 comments on commit fcd2acd

Please sign in to comment.