ChatContact.vue
2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<script setup>
import { useChat } from '@/views/apps/chat/useChat'
import { useChatStore } from '@/views/apps/chat/useChatStore'
const props = defineProps({
isChatContact: {
type: Boolean,
required: false,
default: false,
},
user: {
type: null,
required: true,
},
})
const store = useChatStore()
const { resolveAvatarBadgeVariant } = useChat()
const isChatContactActive = computed(() => {
const isActive = store.activeChat?.contact.id === props.user.id
if (!props.isChatContact)
return !store.activeChat?.chat && isActive
return isActive
})
</script>
<template>
<li
:key="store.chatsContacts.length"
class="chat-contact cursor-pointer d-flex align-center"
:class="{ 'chat-contact-active': isChatContactActive }"
:data-x="store.chatsContacts.length"
>
<VBadge
dot
location="bottom right"
offset-x="3"
offset-y="3"
:color="resolveAvatarBadgeVariant(props.user.status)"
bordered
:model-value="props.isChatContact"
>
<VAvatar
size="40"
:variant="!props.user.avatar ? 'tonal' : undefined"
:color="!props.user.avatar ? resolveAvatarBadgeVariant(props.user.status) : undefined"
>
<VImg
v-if="props.user.avatar"
:src="props.user.avatar"
alt="John Doe"
/>
<span v-else>{{ avatarText(user.fullName) }}</span>
</VAvatar>
</VBadge>
<div class="flex-grow-1 ms-4 overflow-hidden">
<p class="text-base mb-0">
{{ props.user.fullName }}
</p>
<span class="d-block text-body-2 text-truncate">{{ props.isChatContact && 'chat' in props.user ? props.user.chat.lastMessage.message : props.user.about }}</span>
</div>
<div
v-if="props.isChatContact && 'chat' in props.user"
class="d-flex flex-column align-self-start"
>
<span class="d-block text-sm text-disabled whitespace-no-wrap">{{ formatDateToMonthShort(props.user.chat.lastMessage.time) }}</span>
<VBadge
v-if="props.user.chat.unseenMsgs"
color="error"
inline
:content="props.user.chat.unseenMsgs"
class="ms-auto"
/>
</div>
</li>
</template>
<style lang="scss">
@use "@styles/variables/vuetify.scss";
@use "@core/scss/base/mixins";
@use "vuetify/lib/styles/tools/states" as vuetifyStates;
.chat-contact {
border-radius: vuetify.$border-radius-root;
padding-block: 8px;
padding-inline: var(--chat-content-spacing-x);
@include mixins.before-pseudo;
@include vuetifyStates.states($active: false);
&.chat-contact-active {
@include mixins.elevation(2);
background: rgb(var(--v-theme-primary));
color: #fff;
--v-theme-on-background: #fff;
.v-avatar {
background: #fff;
}
}
.v-badge--bordered .v-badge__badge::after {
color: #fff;
}
}
</style>