feat: Attachment view improvements (#7314)
This commit is contained in:
@@ -29,13 +29,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.modal-image {
|
.modal-image {
|
||||||
max-height: 80vh;
|
max-height: 76vh;
|
||||||
max-width: 80vw;
|
max-width: 76vw;
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-video {
|
.modal-video {
|
||||||
max-height: 80vh;
|
max-height: 76vh;
|
||||||
max-width: 80vw;
|
max-width: 76vw;
|
||||||
}
|
}
|
||||||
|
|
||||||
&::before {
|
&::before {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
>
|
>
|
||||||
<div :class="modalContainerClassName" @click.stop>
|
<div :class="modalContainerClassName" @click.stop>
|
||||||
<woot-button
|
<woot-button
|
||||||
|
v-if="showCloseButton"
|
||||||
color-scheme="secondary"
|
color-scheme="secondary"
|
||||||
icon="dismiss"
|
icon="dismiss"
|
||||||
variant="clear"
|
variant="clear"
|
||||||
@@ -28,6 +29,10 @@ export default {
|
|||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
show: Boolean,
|
show: Boolean,
|
||||||
|
showCloseButton: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
onClose: {
|
onClose: {
|
||||||
type: Function,
|
type: Function,
|
||||||
required: true,
|
required: true,
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
{{ $t('CONVERSATION.UPLOADING_ATTACHMENTS') }}
|
{{ $t('CONVERSATION.UPLOADING_ATTACHMENTS') }}
|
||||||
</span>
|
</span>
|
||||||
<div v-if="!isPending && hasAttachments">
|
<div v-if="!isPending && hasAttachments">
|
||||||
<div v-for="attachment in data.attachments" :key="attachment.id">
|
<div v-for="attachment in attachments" :key="attachment.id">
|
||||||
<bubble-image-audio-video
|
<bubble-image-audio-video
|
||||||
v-if="isAttachmentImageVideoAudio(attachment.file_type)"
|
v-if="isAttachmentImageVideoAudio(attachment.file_type)"
|
||||||
:attachment="attachment"
|
:attachment="attachment"
|
||||||
@@ -199,6 +199,14 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
attachments() {
|
||||||
|
// Here it is used to get sender and created_at for each attachment
|
||||||
|
return this.data?.attachments.map(attachment => ({
|
||||||
|
...attachment,
|
||||||
|
sender: this.data.sender || {},
|
||||||
|
created_at: this.data.created_at || '',
|
||||||
|
}));
|
||||||
|
},
|
||||||
shouldRenderMessage() {
|
shouldRenderMessage() {
|
||||||
return (
|
return (
|
||||||
this.hasAttachments ||
|
this.hasAttachments ||
|
||||||
|
|||||||
@@ -1,12 +1,53 @@
|
|||||||
<template>
|
<template>
|
||||||
<woot-modal full-width :show.sync="show" :on-close="onClose">
|
<woot-modal
|
||||||
|
full-width
|
||||||
|
:show.sync="show"
|
||||||
|
:show-close-button="false"
|
||||||
|
:on-close="onClose"
|
||||||
|
>
|
||||||
<div v-on-clickaway="onClose" class="gallery-modal--wrap" @click="onClose">
|
<div v-on-clickaway="onClose" class="gallery-modal--wrap" @click="onClose">
|
||||||
|
<div class="gallery-modal--header">
|
||||||
|
<div class="header-info--wrap" @click.stop>
|
||||||
|
<thumbnail
|
||||||
|
:username="senderDetails.name"
|
||||||
|
:src="senderDetails.avatar"
|
||||||
|
/>
|
||||||
|
<div class="header-info">
|
||||||
|
<h3 class="sub-block-title sender-name">
|
||||||
|
<span class="text-truncate">{{ senderDetails.name }}</span>
|
||||||
|
</h3>
|
||||||
|
<span class="time-stamp text-truncate">{{ readableTime }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="file-name--header text-block-title">
|
||||||
|
<span class="text-truncate">
|
||||||
|
{{ fileNameFromDataUrl }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="header-actions" @click.stop>
|
||||||
|
<woot-button
|
||||||
|
size="large"
|
||||||
|
color-scheme="secondary"
|
||||||
|
variant="clear"
|
||||||
|
icon="arrow-download"
|
||||||
|
@click="onClickDownload"
|
||||||
|
/>
|
||||||
|
<woot-button
|
||||||
|
size="large"
|
||||||
|
color-scheme="secondary"
|
||||||
|
variant="clear"
|
||||||
|
icon="dismiss"
|
||||||
|
@click="onClose"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="gallery-modal--body">
|
||||||
<div class="attachment-toggle--button">
|
<div class="attachment-toggle--button">
|
||||||
<woot-button
|
<woot-button
|
||||||
v-if="hasMoreThanOneAttachment"
|
v-if="hasMoreThanOneAttachment"
|
||||||
size="large"
|
size="large"
|
||||||
variant="smooth"
|
variant="smooth"
|
||||||
color-scheme="secondary"
|
color-scheme="primary"
|
||||||
icon="chevron-left"
|
icon="chevron-left"
|
||||||
:disabled="activeImageIndex === 0"
|
:disabled="activeImageIndex === 0"
|
||||||
@click.stop="
|
@click.stop="
|
||||||
@@ -21,15 +62,15 @@
|
|||||||
<div class="attachment-view">
|
<div class="attachment-view">
|
||||||
<img
|
<img
|
||||||
v-if="isImage"
|
v-if="isImage"
|
||||||
:key="attachmentSrc"
|
:key="activeAttachment.message_id"
|
||||||
:src="attachmentSrc"
|
:src="activeAttachment.data_url"
|
||||||
class="modal-image skip-context-menu"
|
class="modal-image skip-context-menu"
|
||||||
@click.stop
|
@click.stop
|
||||||
/>
|
/>
|
||||||
<video
|
<video
|
||||||
v-if="isVideo"
|
v-if="isVideo"
|
||||||
:key="attachmentSrc"
|
:key="activeAttachment.message_id"
|
||||||
:src="attachmentSrc"
|
:src="activeAttachment.data_url"
|
||||||
controls
|
controls
|
||||||
playsInline
|
playsInline
|
||||||
class="modal-video skip-context-menu"
|
class="modal-video skip-context-menu"
|
||||||
@@ -37,12 +78,12 @@
|
|||||||
/>
|
/>
|
||||||
<audio
|
<audio
|
||||||
v-if="isAudio"
|
v-if="isAudio"
|
||||||
:key="attachmentSrc"
|
:key="activeAttachment.message_id"
|
||||||
controls
|
controls
|
||||||
class="skip-context-menu"
|
class="skip-context-menu"
|
||||||
@click.stop
|
@click.stop
|
||||||
>
|
>
|
||||||
<source :src="`${attachmentSrc}?t=${Date.now()}`" />
|
<source :src="`${activeAttachment.data_url}?t=${Date.now()}`" />
|
||||||
</audio>
|
</audio>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -51,7 +92,7 @@
|
|||||||
v-if="hasMoreThanOneAttachment"
|
v-if="hasMoreThanOneAttachment"
|
||||||
size="large"
|
size="large"
|
||||||
variant="smooth"
|
variant="smooth"
|
||||||
color-scheme="secondary"
|
color-scheme="primary"
|
||||||
:disabled="activeImageIndex === allAttachments.length - 1"
|
:disabled="activeImageIndex === allAttachments.length - 1"
|
||||||
icon="chevron-right"
|
icon="chevron-right"
|
||||||
@click.stop="
|
@click.stop="
|
||||||
@@ -63,17 +104,28 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="gallery-modal--footer">
|
||||||
|
<div class="header-count text-block-title">
|
||||||
|
<span class="count">
|
||||||
|
{{ `${activeImageIndex + 1} / ${allAttachments.length}` }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</woot-modal>
|
</woot-modal>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { mixin as clickaway } from 'vue-clickaway';
|
import { mixin as clickaway } from 'vue-clickaway';
|
||||||
|
import { mapGetters } from 'vuex';
|
||||||
import {
|
import {
|
||||||
isEscape,
|
isEscape,
|
||||||
hasPressedArrowLeftKey,
|
hasPressedArrowLeftKey,
|
||||||
hasPressedArrowRightKey,
|
hasPressedArrowRightKey,
|
||||||
} from 'shared/helpers/KeyboardHelpers';
|
} from 'shared/helpers/KeyboardHelpers';
|
||||||
import eventListenerMixins from 'shared/mixins/eventListenerMixins';
|
import eventListenerMixins from 'shared/mixins/eventListenerMixins';
|
||||||
|
import timeMixin from 'dashboard/mixins/time';
|
||||||
|
|
||||||
|
import Thumbnail from 'dashboard/components/widgets/Thumbnail';
|
||||||
|
|
||||||
const ALLOWED_FILE_TYPES = {
|
const ALLOWED_FILE_TYPES = {
|
||||||
IMAGE: 'image',
|
IMAGE: 'image',
|
||||||
@@ -82,7 +134,10 @@ const ALLOWED_FILE_TYPES = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
mixins: [eventListenerMixins, clickaway],
|
components: {
|
||||||
|
Thumbnail,
|
||||||
|
},
|
||||||
|
mixins: [eventListenerMixins, clickaway, timeMixin],
|
||||||
props: {
|
props: {
|
||||||
show: {
|
show: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
@@ -99,18 +154,29 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
attachmentSrc: '',
|
activeAttachment: {},
|
||||||
activeFileType: '',
|
activeFileType: '',
|
||||||
activeImageIndex:
|
activeImageIndex:
|
||||||
this.allAttachments.findIndex(
|
this.allAttachments.findIndex(
|
||||||
attachment => attachment.id === this.attachment.id
|
attachment => attachment.message_id === this.attachment.message_id
|
||||||
) || 0,
|
) || 0,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
...mapGetters({
|
||||||
|
currentUser: 'getCurrentUser',
|
||||||
|
}),
|
||||||
hasMoreThanOneAttachment() {
|
hasMoreThanOneAttachment() {
|
||||||
return this.allAttachments.length > 1;
|
return this.allAttachments.length > 1;
|
||||||
},
|
},
|
||||||
|
readableTime() {
|
||||||
|
if (!this.activeAttachment.created_at) return '';
|
||||||
|
const time = this.messageTimestamp(
|
||||||
|
this.activeAttachment.created_at,
|
||||||
|
'LLL d yyyy, h:mm a'
|
||||||
|
);
|
||||||
|
return time || '';
|
||||||
|
},
|
||||||
isImage() {
|
isImage() {
|
||||||
return this.activeFileType === ALLOWED_FILE_TYPES.IMAGE;
|
return this.activeFileType === ALLOWED_FILE_TYPES.IMAGE;
|
||||||
},
|
},
|
||||||
@@ -120,6 +186,21 @@ export default {
|
|||||||
isAudio() {
|
isAudio() {
|
||||||
return this.activeFileType === ALLOWED_FILE_TYPES.AUDIO;
|
return this.activeFileType === ALLOWED_FILE_TYPES.AUDIO;
|
||||||
},
|
},
|
||||||
|
senderDetails() {
|
||||||
|
const { name, available_name: availableName, avatar_url, thumbnail, id } =
|
||||||
|
this.activeAttachment?.sender || this.attachment?.sender;
|
||||||
|
const currentUserID = this.currentUser?.id;
|
||||||
|
return {
|
||||||
|
name: currentUserID === id ? 'You' : name || availableName || '',
|
||||||
|
avatar: thumbnail || avatar_url || '',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
fileNameFromDataUrl() {
|
||||||
|
const { data_url: dataUrl } = this.activeAttachment;
|
||||||
|
if (!dataUrl) return '';
|
||||||
|
const fileName = dataUrl?.split('/').pop();
|
||||||
|
return fileName || '';
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.setImageAndVideoSrc(this.attachment);
|
this.setImageAndVideoSrc(this.attachment);
|
||||||
@@ -140,7 +221,7 @@ export default {
|
|||||||
if (!Object.values(ALLOWED_FILE_TYPES).includes(type)) {
|
if (!Object.values(ALLOWED_FILE_TYPES).includes(type)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.attachmentSrc = attachment.data_url;
|
this.activeAttachment = attachment;
|
||||||
this.activeFileType = type;
|
this.activeFileType = type;
|
||||||
},
|
},
|
||||||
onKeyDownHandler(e) {
|
onKeyDownHandler(e) {
|
||||||
@@ -158,29 +239,121 @@ export default {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onClickDownload() {
|
||||||
|
const { file_type: type, data_url: url } = this.activeAttachment;
|
||||||
|
if (!Object.values(ALLOWED_FILE_TYPES).includes(type)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.download = `attachment.${type}`;
|
||||||
|
link.click();
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.gallery-modal--wrap {
|
.gallery-modal--wrap {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: column;
|
||||||
align-items: center;
|
|
||||||
width: inherit;
|
|
||||||
height: inherit;
|
height: inherit;
|
||||||
|
width: inherit;
|
||||||
|
|
||||||
|
.gallery-modal--header {
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
height: var(--space-jumbo);
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: var(--space-small) var(--space-medium);
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
.header-info--wrap {
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
min-width: var(--space-giga);
|
||||||
|
|
||||||
|
.header-info {
|
||||||
|
align-items: flex-start;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
margin-left: var(--space-small);
|
||||||
|
|
||||||
|
.sender-name {
|
||||||
|
display: inline-block;
|
||||||
|
line-height: 1.4;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
text-transform: capitalize;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time-stamp {
|
||||||
|
color: var(--s-400);
|
||||||
|
font-size: var(--font-size-mini);
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-name--header {
|
||||||
|
align-items: center;
|
||||||
|
color: var(--s-700);
|
||||||
|
display: flex;
|
||||||
|
font-weight: var(--font-weight-bold);
|
||||||
|
justify-content: flex-start;
|
||||||
|
min-width: 0;
|
||||||
|
padding: var(--space-smaller);
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-actions {
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
gap: var(--space-small);
|
||||||
|
justify-content: flex-end;
|
||||||
|
min-width: var(--space-giga);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.gallery-modal--body {
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
height: 100%;
|
||||||
|
justify-content: center;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gallery-modal--footer {
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
height: var(--space-jumbo);
|
||||||
|
justify-content: center;
|
||||||
|
padding: var(--space-small) var(--space-medium);
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
.header-count {
|
||||||
|
align-items: center;
|
||||||
|
border-radius: var(--border-radius-small);
|
||||||
|
background-color: var(--s-25);
|
||||||
|
color: var(--s-600);
|
||||||
|
display: flex;
|
||||||
|
font-weight: var(--font-weight-bold);
|
||||||
|
justify-content: center;
|
||||||
|
min-width: 8rem;
|
||||||
|
padding: var(--space-smaller);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.attachments-viewer {
|
.attachments-viewer {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
|
||||||
|
|
||||||
.attachment-view {
|
.attachment-view {
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
|
|
||||||
img {
|
img {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
@@ -192,10 +365,10 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.attachment-toggle--button {
|
.attachment-toggle--button {
|
||||||
width: var(--space-mega);
|
|
||||||
min-width: var(--space-mega);
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
min-width: var(--space-mega);
|
||||||
|
width: var(--space-mega);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user