EmailView.vue
11.6 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
<script setup>
import { PerfectScrollbar } from 'vue3-perfect-scrollbar'
import { useEmail } from '@/views/apps/email/useEmail'
const props = defineProps({
email: {
type: null,
required: true,
},
emailMeta: {
type: Object,
required: true,
},
})
const emit = defineEmits([
'refresh',
'navigated',
'close',
'trash',
'unread',
'read',
'star',
'unstar',
])
const emailReply = ref('')
const showReplyBox = ref(false)
const showReplyCard = ref(true)
const { updateEmailLabels } = useEmail()
const { labels, resolveLabelColor, emailMoveToFolderActions, shallShowMoveToActionFor, moveSelectedEmailTo } = useEmail()
const handleMoveMailsTo = async action => {
await moveSelectedEmailTo(action, [props.email.id])
emit('refresh')
emit('close')
}
const updateMailLabel = async label => {
await updateEmailLabels([props.email.id], label)
emit('refresh')
}
</script>
<template>
<!-- ℹ️ calc(100% - 256px) => 265px is left sidebar width -->
<VNavigationDrawer
temporary
:model-value="!!props.email"
location="right"
:scrim="false"
floating
class="email-view"
>
<template v-if="props.email">
<!-- 👉 header -->
<div class="email-view-header d-flex align-center px-5 py-4">
<IconBtn
class="me-2 flip-in-rtl"
@click="$emit('close'); showReplyBox = false; showReplyCard = true; emailReply = ''"
>
<VIcon icon="ri-arrow-left-s-line" />
</IconBtn>
<div class="d-flex align-center flex-wrap flex-grow-1 overflow-hidden gap-2">
<h6 class="text-h6 font-weight-regular text-truncate">
{{ props.email.subject }}
</h6>
<div class="d-flex flex-wrap gap-2">
<VChip
v-for="label in props.email.labels"
:key="label"
:color="resolveLabelColor(label)"
size="small"
class="text-capitalize flex-shrink-0"
>
{{ label }}
</VChip>
</div>
</div>
<div class="d-flex align-center gap-2">
<IconBtn
variant="plain"
:disabled="!props.emailMeta.hasPreviousEmail"
class="flip-in-rtl"
@click="$emit('navigated', 'previous')"
>
<VIcon icon="ri-arrow-left-s-line" />
</IconBtn>
<IconBtn
variant="plain"
class="flip-in-rtl"
:disabled="!props.emailMeta.hasNextEmail"
@click="$emit('navigated', 'next')"
>
<VIcon icon="ri-arrow-right-s-line" />
</IconBtn>
</div>
</div>
<VDivider />
<!-- 👉 Action bar -->
<div class="email-view-action-bar d-flex align-center text-medium-emphasis gap-1 px-5">
<!-- Trash -->
<IconBtn
v-show="!props.email.isDeleted"
@click="$emit('trash'); $emit('close')"
>
<VIcon icon="ri-delete-bin-7-line" />
<VTooltip
activator="parent"
location="top"
>
Delete Mail
</VTooltip>
</IconBtn>
<!-- Read/Unread -->
<IconBtn @click.stop="$emit('unread'); $emit('close')">
<VIcon icon="ri-mail-line" />
<VTooltip
activator="parent"
location="top"
>
Mark as Unread
</VTooltip>
</IconBtn>
<!-- Move to folder -->
<IconBtn>
<VIcon icon="ri-folder-line" />
<VTooltip
activator="parent"
location="top"
>
Move to
</VTooltip>
<VMenu activator="parent">
<VList density="compact">
<template
v-for="moveTo in emailMoveToFolderActions"
:key="moveTo.title"
>
<VListItem
:class="shallShowMoveToActionFor(moveTo.action) ? 'd-flex' : 'd-none'"
class="align-center"
href="#"
@click="handleMoveMailsTo(moveTo.action)"
>
<template #prepend>
<VIcon
:icon="moveTo.icon"
class="me-2"
size="20"
/>
</template>
<VListItemTitle class="text-capitalize">
{{ moveTo.action }}
</VListItemTitle>
</VListItem>
</template>
</VList>
</VMenu>
</IconBtn>
<!-- Update labels -->
<IconBtn>
<VIcon icon="ri-price-tag-3-line" />
<VTooltip
activator="parent"
location="top"
>
Label
</VTooltip>
<VMenu activator="parent">
<VList density="compact">
<VListItem
v-for="label in labels"
:key="label.title"
href="#"
@click.stop="updateMailLabel(label.title)"
>
<template #prepend>
<VBadge
inline
:color="resolveLabelColor(label.title)"
dot
/>
</template>
<VListItemTitle class="ms-2 text-capitalize">
{{ label.title }}
</VListItemTitle>
</VListItem>
</VList>
</VMenu>
</IconBtn>
<VSpacer />
<div class="d-flex align-center gap-x-1">
<!-- Star/Unstar -->
<IconBtn
:color="props.email.isStarred ? 'warning' : 'default'"
@click="props.email?.isStarred ? $emit('unstar') : $emit('star'); $emit('refresh')"
>
<VIcon
:color="props.email.isStarred ? 'warning' : '' "
icon="ri-star-line"
/>
</IconBtn>
<MoreBtn />
</div>
</div>
<VDivider />
<!-- 👉 Mail Content -->
<PerfectScrollbar
tag="div"
class="mail-content-container flex-grow-1 pa-sm-12 pa-6"
:options="{ wheelPropagation: false }"
>
<VCard class="mb-4">
<VCardText class="mail-header">
<div class="d-flex align-start">
<VAvatar
size="38"
class="me-3"
>
<VImg
:src="props.email.from.avatar"
:alt="props.email.from.name"
/>
</VAvatar>
<div class="d-flex flex-wrap flex-grow-1 overflow-hidden">
<div class="text-truncate">
<h6 class="text-h6 font-weight-regular text-truncate">
{{ props.email.from.name }}
</h6>
<p class="text-body-2 mb-0">
{{ props.email.from.email }}
</p>
</div>
<VSpacer />
<div class="d-flex align-center">
<span class="text-disabled me-4">{{ formatDate(props.email.time) }}</span>
<IconBtn v-show="props.email.attachments.length">
<VIcon icon="ri-attachment-2" />
</IconBtn>
</div>
</div>
<MoreBtn class="align-self-sm-center" />
</div>
</VCardText>
<VDivider />
<VCardText>
<!-- eslint-disable vue/no-v-html -->
<div class="text-body-1 font-weight-medium text-truncate mb-4">
{{ props.email.from.name }},
</div>
<div
class="text-base"
v-html="props.email.message"
/>
<!-- eslint-enable -->
</VCardText>
<template v-if="props.email.attachments.length">
<VDivider />
<VCardText class="d-flex flex-column gap-y-4 pt-4">
<span>2 Attachments</span>
<div
v-for="attachment in props.email.attachments"
:key="attachment.fileName"
class="d-flex align-center"
>
<VImg
:src="attachment.thumbnail"
:alt="attachment.fileName"
aspect-ratio="1"
max-height="24"
max-width="24"
class="me-2"
/>
<span>{{ attachment.fileName }}</span>
</div>
</VCardText>
</template>
</VCard>
<!-- Reply or Forward -->
<VCard v-show="showReplyCard">
<VCardText class="font-weight-medium text-high-emphasis">
<div class="text-base">
Click here to <span
class="text-primary cursor-pointer"
@click="showReplyBox = !showReplyBox; showReplyCard = !showReplyCard"
>
Reply
</span> or <span class="text-primary cursor-pointer">
Forward
</span>
</div>
</VCardText>
</VCard>
<VCard v-if="showReplyBox">
<VCardText>
<h6 class="text-body-1 text-high-emphasis mb-4">
Reply to {{ email?.from.name }}
</h6>
<TiptapEditor
v-model="emailReply"
placeholder="Write your message..."
:is-divider="false"
/>
<div class="d-flex justify-end gap-4 pt-2 flex-wrap">
<IconBtn
icon="ri-delete-bin-7-line"
@click="showReplyBox = !showReplyBox; showReplyCard = !showReplyCard; emailReply = ''"
/>
<VBtn
variant="text"
color="secondary"
>
<template #prepend>
<VIcon
icon="ri-attachment-2"
class="text-high-emphasis"
/>
</template>
Attachments
</VBtn>
<VBtn append-icon="ri-send-plane-line">
Send
</VBtn>
</div>
</VCardText>
</VCard>
</PerfectScrollbar>
</template>
</VNavigationDrawer>
</template>
<style lang="scss">
.email-view {
&:not(.v-navigation-drawer--active) {
transform: translateX(110%) !important;
}
inline-size: 100% !important;
@media only screen and (min-width: 1280px) {
inline-size: calc(100% - 256px) !important;
}
.editor {
padding-block-start: 0 !important;
padding-inline: 0 !important;
}
.v-navigation-drawer__content {
display: flex;
flex-direction: column;
}
.ProseMirror {
block-size: 100px;
overflow-y: auto;
p {
margin-block-end: 0;
}
p.is-editor-empty:first-child::before {
block-size: 0;
color: #adb5bd;
content: attr(data-placeholder);
float: inline-start;
pointer-events: none;
}
ul,
ol {
padding-inline: 1.125rem;
}
}
.is-active {
border-color: rgba(var(--v-theme-primary), var(--v-border-opacity)) !important;
background-color: rgba(var(--v-theme-primary), var(--v-activated-opacity));
color: rgb(var(--v-theme-primary));
}
.ProseMirror-focused {
outline: none !important;
}
}
.email-view-action-bar {
min-block-size: 54px;
}
.mail-content-container {
background-color: rgb(var(--v-theme-on-background), var(--v-hover-opacity));
.mail-header {
min-block-size: 84px;
}
.v-card {
border: 1px solid rgba(var(--v-theme-on-surface), var(--v-border-opacity));
}
}
</style>