From b9742395c56f3467f50ecc784e397119d318406f Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 21 Feb 2026 06:58:05 +0100 Subject: [PATCH] shorten group names when too long --- .../UserTeaser/UserTeaserNonAnonymous.vue | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/webapp/components/UserTeaser/UserTeaserNonAnonymous.vue b/webapp/components/UserTeaser/UserTeaserNonAnonymous.vue index 4face8d66..cb13acacf 100644 --- a/webapp/components/UserTeaser/UserTeaserNonAnonymous.vue +++ b/webapp/components/UserTeaser/UserTeaserNonAnonymous.vue @@ -30,7 +30,7 @@ {{ $t('group.in') }} - {{ groupName }} + {{ groupNameTruncated }} @@ -88,6 +88,11 @@ export default { injectedDate: { type: Boolean, default: false }, hoverDelay: { type: Number, default: 500 }, }, + data() { + return { + maxGroupChars: 50, + } + }, computed: { ...mapGetters({ isModerator: 'auth/isModerator', @@ -125,11 +130,46 @@ export default { const { name } = this.group || {} return name || this.$t('profile.userAnonym') }, + groupNameTruncated() { + const name = this.groupName + return name.length > this.maxGroupChars + ? name.slice(0, this.maxGroupChars) + '...' + : name + }, }, created() { this.icons = iconRegistry }, + mounted() { + this.calcMaxGroupChars() + window.addEventListener('resize', this.calcMaxGroupChars) + }, + beforeDestroy() { + window.removeEventListener('resize', this.calcMaxGroupChars) + }, methods: { + calcMaxGroupChars() { + this.$nextTick(() => { + if (!this.group) return + const teaserEl = this.$el + if (!teaserEl) return + // Available width = teaser width - avatar(36px) - padding-left(10px) + const availableWidth = teaserEl.clientWidth - 46 + const style = getComputedStyle(teaserEl) + const canvas = document.createElement('canvas') + const ctx = canvas.getContext('2d') + ctx.font = `${style.fontSize} ${style.fontFamily}` + const inTextWidth = ctx.measureText(this.$t('group.in') + ' ').width + const dotsWidth = ctx.measureText('...').width + const space = availableWidth - inTextWidth - dotsWidth + if (space <= 0) { + this.maxGroupChars = 3 + return + } + const avgCharWidth = ctx.measureText('abcdefghijklmnopqrstuvwxyz').width / 26 + this.maxGroupChars = Math.max(3, Math.floor(space / avgCharWidth)) + }) + }, async loadPopover(openMenu) { // Load user data if not already loaded, to avoid flickering await this.$apollo.query({