Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

techdebt(NcAvatar) - optimize avatar wrappers #10602

Merged
merged 6 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 42 additions & 12 deletions src/components/AvatarWrapper/AvatarWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
- @copyright Copyright (c) 2020 Marco Ambrosini <marcoambrosini@icloud.com>
-
- @author Marco Ambrosini <marcoambrosini@icloud.com>
- @author Maksim Sukharev <antreesy.web@gmail.com>
-
- @license GNU AGPL version 3 or any later version
- @license AGPL-3.0-or-later
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
Expand All @@ -20,14 +21,7 @@
-->

<template>
<div class="avatar-wrapper"
:class="{
'avatar-wrapper--offline': offline,
'avatar-wrapper--small': small,
'avatar-wrapper--condensed': condensed,
'avatar-wrapper--highlighted': highlighted,
}"
:style="{'--condensed-overlap': condensedOverlap}">
<div class="avatar-wrapper" :class="avatarClass" :style="{'--condensed-overlap': condensedOverlap}">
<div v-if="iconClass"
class="icon"
:class="[`avatar-${size}px`, iconClass]" />
Expand All @@ -36,6 +30,11 @@
:class="`avatar-${size}px`">
{{ firstLetterOfGuestName }}
</div>
<div v-else-if="isBot"
class="bot"
:class="`avatar-${size}px`">
{{ '>_' }}
</div>
<NcAvatar v-else
:key="id"
:user="id"
Expand All @@ -54,6 +53,8 @@
<script>
import NcAvatar from '@nextcloud/vue/dist/Components/NcAvatar.js'

import { ATTENDEE } from '../../constants.js'

export default {

name: 'AvatarWrapper',
Expand All @@ -79,6 +80,10 @@ export default {
type: Boolean,
default: false,
},
medium: {
type: Boolean,
default: false,
},
condensed: {
type: Boolean,
default: false,
Expand Down Expand Up @@ -122,19 +127,37 @@ export default {
},
computed: {
size() {
return this.small ? 22 : 44
return this.small ? 22 : this.medium ? 32 : 44
},
// Determines which icon is displayed
iconClass() {
if (!this.source || this.source === 'users' || this.isGuest || this.isDeletedUser) {
if (!this.source || this.isUser || this.isBot || this.isGuest || this.isDeletedUser) {
return ''
}
if (this.source === 'emails') {
return 'icon-mail'
}
if (this.source === 'bots' && this.id === 'changelog') {
return 'icon-changelog'
}
// source: groups, circles
return 'icon-contacts'
},
avatarClass() {
return {
'avatar-wrapper--offline': this.offline,
'avatar-wrapper--small': this.small,
'avatar-wrapper--medium': this.medium,
'avatar-wrapper--condensed': this.condensed,
'avatar-wrapper--highlighted': this.highlighted,
}
},
isUser() {
return this.source === 'users' || this.source === ATTENDEE.ACTOR_TYPE.BRIDGED
},
isBot() {
return this.source === 'bots' && this.id !== 'changelog'
},
isGuest() {
return this.source === 'guests'
},
Expand All @@ -161,7 +184,7 @@ export default {
</script>

<style lang="scss" scoped>
@import '../../assets/avatar.scss';
@import '../../assets/avatar';

.avatar-wrapper {
height: 44px;
Expand All @@ -176,6 +199,13 @@ export default {
@include avatar-mixin(22px);
}

&--medium {
height: 32px;
width: 32px;
border-radius: 32px;
@include avatar-mixin(32px);
}

&--condensed {
width: unset;
height: unset;
Expand Down
53 changes: 16 additions & 37 deletions src/components/ConversationIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
-->

<template>
<div ref="conversation-icon"
class="conversation-icon"
<div class="conversation-icon"
:style="{'--icon-size': `${size}px`}"
:class="{'offline': offline}">
<div v-if="iconClass"
Expand All @@ -45,18 +44,16 @@
:disable-menu="disableMenu"
:display-name="item.displayName"
:preloaded-user-status="preloadedUserStatus"
:show-user-status="showUserStatus"
:show-user-status-compact="disableMenu"
:show-user-status="!hideUserStatus"
:show-user-status-compact="!showUserOnlineStatus"
:menu-container="menuContainer"
menu-position="left"
class="conversation-icon__avatar" />
<div v-if="showCall"
class="overlap-icon">
<div v-if="showCall" class="overlap-icon">
<VideoIcon :size="20" :fill-color="'#E9322D'" />
<span class="hidden-visually">{{ t('spreed', 'Call in progress') }}</span>
</div>
<div v-else-if="showFavorite"
class="overlap-icon">
<div v-else-if="showFavorite" class="overlap-icon">
<Star :size="20" :fill-color="'#FFCC00'" />
<span class="hidden-visually">{{ t('spreed', 'Favorite') }}</span>
</div>
Expand Down Expand Up @@ -101,13 +98,18 @@ export default {
},

disableMenu: {
type: Boolean,
default: true,
},

hideUserStatus: {
type: Boolean,
default: false,
},

showUserStatus: {
showUserOnlineStatus: {
type: Boolean,
default: true,
default: false,
},

item: {
Expand All @@ -130,22 +132,12 @@ export default {
default: false,
},

/**
* Passing in true will make this component fill all the available space in its container.
* This is not reactive as it will take the size of the container once mounted.
*/
isBig: {
type: Boolean,
default: false,
size: {
type: Number,
default: 44,
},
},

data() {
return {
parentElement: undefined,
}
},

computed: {
showCall() {
return !this.hideCall && this.item.hasCall
Expand All @@ -156,7 +148,7 @@ export default {
},

preloadedUserStatus() {
if (this.showUserStatus && Object.prototype.hasOwnProperty.call(this.item, 'statusMessage')) {
if (!this.hideUserStatus && Object.prototype.hasOwnProperty.call(this.item, 'statusMessage')) {
// We preloaded the status
return {
status: this.item.status || null,
Expand Down Expand Up @@ -217,14 +209,6 @@ export default {
return undefined
},

size() {
if (this.isBig && this.parentElement) {
return Math.min(this.parentElement.clientHeight, this.parentElement.clientWidth)
} else {
return 44
}
},

isOneToOne() {
return this.item.type === CONVERSATION.TYPE.ONE_TO_ONE
},
Expand All @@ -242,11 +226,6 @@ export default {
})
},
},

mounted() {
// Get the size of the parent once the component is mounted
this.parentElement = this.$refs['conversation-icon'].parentElement
},
}
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
</div>
<ConversationIcon v-else-if="!loading"
:item="conversation"
:is-big="true"
:show-user-status="false"
:disable-menu="true" />
:size="180"
hide-user-status />
<div v-else class="icon-loading" />
</div>
<VueCropper v-show="showCropper"
Expand Down
4 changes: 1 addition & 3 deletions src/components/GuestWelcomeWindow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
size="small">
<div class="modal__content">
<div class="conversation-information">
<ConversationIcon :item="conversation"
:show-user-status="false"
disable-menu />
<ConversationIcon :item="conversation" hide-user-status />
<h2>{{ conversationDisplayName }}</h2>
</div>
<p class="description">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@
:counter-type="counterType"
@click="onClick">
<template #icon>
<ConversationIcon :item="item"
:hide-favorite="false"
:hide-call="false"
:disable-menu="true" />
<ConversationIcon :item="item" :hide-favorite="false" :hide-call="false" />
</template>
<template #subtitle>
<strong v-if="item.unreadMessages"
Expand Down
6 changes: 3 additions & 3 deletions src/components/LeftSidebar/LeftSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
:title="item.label"
@click="createAndJoinConversation(item)">
<template #icon>
<ConversationIcon :item="iconData(item)" disable-menu />
<ConversationIcon :item="iconData(item)" />
</template>
</NcListItem>
</template>
Expand All @@ -187,7 +187,7 @@
:title="item.label"
@click="createAndJoinConversation(item)">
<template #icon>
<ConversationIcon :item="iconData(item)" disable-menu />
<ConversationIcon :item="iconData(item)" />
</template>
</NcListItem>
</template>
Expand All @@ -201,7 +201,7 @@
:title="item.label"
@click="createAndJoinConversation(item)">
<template #icon>
<ConversationIcon :item="iconData(item)" disable-menu />
<ConversationIcon :item="iconData(item)" />
</template>
</NcListItem>
</template>
Expand Down
Loading
Loading