diff --git a/app/javascript/dashboard/components-next/message/bubbles/Image.vue b/app/javascript/dashboard/components-next/message/bubbles/Image.vue index ce05071ee..5727fd9e8 100644 --- a/app/javascript/dashboard/components-next/message/bubbles/Image.vue +++ b/app/javascript/dashboard/components-next/message/bubbles/Image.vue @@ -18,6 +18,7 @@ const attachment = computed(() => { const hasError = ref(false); const showGallery = ref(false); +const isDownloading = ref(false); const handleError = () => { hasError.value = true; @@ -26,7 +27,14 @@ const handleError = () => { const downloadAttachment = async () => { const { fileType, dataUrl, extension } = attachment.value; - downloadFile({ url: dataUrl, type: fileType, extension }); + try { + isDownloading.value = true; + await downloadFile({ url: dataUrl, type: fileType, extension }); + } catch (error) { + // error + } finally { + isDownloading.value = false; + } }; @@ -60,7 +68,9 @@ const downloadAttachment = async () => { slate icon="i-lucide-download" class="opacity-60" - @click="downloadAttachment" + :is-loading="isDownloading" + :disabled="isDownloading" + @click.stop="downloadAttachment" /> diff --git a/app/javascript/dashboard/components/widgets/conversation/components/GalleryView.vue b/app/javascript/dashboard/components/widgets/conversation/components/GalleryView.vue index 200984f4c..1b156d6ff 100644 --- a/app/javascript/dashboard/components/widgets/conversation/components/GalleryView.vue +++ b/app/javascript/dashboard/components/widgets/conversation/components/GalleryView.vue @@ -5,6 +5,7 @@ import { useKeyboardEvents } from 'dashboard/composables/useKeyboardEvents'; import { messageTimestamp } from 'shared/helpers/timeHelper'; import { downloadFile } from '@chatwoot/utils'; +import NextButton from 'dashboard/components-next/button/Button.vue'; import Thumbnail from 'dashboard/components/widgets/Thumbnail.vue'; const props = defineProps({ @@ -33,6 +34,7 @@ const ALLOWED_FILE_TYPES = { const MAX_ZOOM_LEVEL = 2; const MIN_ZOOM_LEVEL = 1; +const isDownloading = ref(false); const zoomScale = ref(1); const activeAttachment = ref({}); const activeFileType = ref(''); @@ -117,12 +119,20 @@ const onClickChangeAttachment = (attachment, index) => { zoomScale.value = 1; }; -const onClickDownload = () => { +const onClickDownload = async () => { const { file_type: type, data_url: url, extension } = activeAttachment.value; if (!Object.values(ALLOWED_FILE_TYPES).includes(type)) { return; } - downloadFile({ url, type, extension }); + + try { + isDownloading.value = true; + await downloadFile({ url, type, extension }); + } catch (error) { + // error + } finally { + isDownloading.value = false; + } }; const onRotate = type => { @@ -162,6 +172,12 @@ const onZoom = scale => { }; const onClickZoomImage = () => { + // If already at max zoom, clicking should zoom out to minimum + if (zoomScale.value >= MAX_ZOOM_LEVEL) { + zoomScale.value = MIN_ZOOM_LEVEL; + return; + } + // Otherwise zoom in onZoom(0.1); }; @@ -211,7 +227,6 @@ onMounted(() => { :on-close="onClose" >