mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-04-06 01:25:38 +00:00
just cut group name and save some logic
This commit is contained in:
parent
3b472a26ab
commit
7bde77d24e
@ -84,6 +84,8 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.info {
|
.info {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
@ -136,6 +138,7 @@ export default {
|
|||||||
|
|
||||||
.group-info {
|
.group-info {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
align-self: stretch;
|
||||||
align-items: baseline;
|
align-items: baseline;
|
||||||
gap: 4px;
|
gap: 4px;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
|||||||
@ -30,7 +30,7 @@
|
|||||||
<span v-if="group" class="group-info">
|
<span v-if="group" class="group-info">
|
||||||
<span class="text">{{ $t('group.in') }}</span>
|
<span class="text">{{ $t('group.in') }}</span>
|
||||||
<nuxt-link :to="groupLink" class="group-link" :title="groupName">
|
<nuxt-link :to="groupLink" class="group-link" :title="groupName">
|
||||||
{{ groupNameTruncated }}
|
{{ groupName }}
|
||||||
</nuxt-link>
|
</nuxt-link>
|
||||||
</span>
|
</span>
|
||||||
<!-- eslint-disable-next-line prettier/prettier -->
|
<!-- eslint-disable-next-line prettier/prettier -->
|
||||||
@ -88,11 +88,6 @@ export default {
|
|||||||
injectedDate: { type: Boolean, default: false },
|
injectedDate: { type: Boolean, default: false },
|
||||||
hoverDelay: { type: Number, default: 500 },
|
hoverDelay: { type: Number, default: 500 },
|
||||||
},
|
},
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
maxGroupChars: 50,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters({
|
...mapGetters({
|
||||||
isModerator: 'auth/isModerator',
|
isModerator: 'auth/isModerator',
|
||||||
@ -130,44 +125,11 @@ export default {
|
|||||||
const { name } = this.group || {}
|
const { name } = this.group || {}
|
||||||
return name || this.$t('profile.userAnonym')
|
return name || this.$t('profile.userAnonym')
|
||||||
},
|
},
|
||||||
groupNameTruncated() {
|
|
||||||
const name = this.groupName
|
|
||||||
return name.length > this.maxGroupChars ? name.slice(0, this.maxGroupChars) + '...' : name
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.icons = iconRegistry
|
this.icons = iconRegistry
|
||||||
},
|
},
|
||||||
mounted() {
|
|
||||||
this.calcMaxGroupChars()
|
|
||||||
window.addEventListener('resize', this.calcMaxGroupChars)
|
|
||||||
},
|
|
||||||
beforeDestroy() {
|
|
||||||
window.removeEventListener('resize', this.calcMaxGroupChars)
|
|
||||||
},
|
|
||||||
methods: {
|
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) {
|
async loadPopover(openMenu) {
|
||||||
// Load user data if not already loaded, to avoid flickering
|
// Load user data if not already loaded, to avoid flickering
|
||||||
await this.$apollo.query({
|
await this.$apollo.query({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user