mirror of
https://github.com/lingble/chatwoot.git
synced 2025-10-30 18:47:51 +00:00
To test this, set the `useNextBubble` value to `true` in the
localstorage. Here's a quick command to run in the console
```js
localStorage.setItem('useNextBubble', true)
```
```js
localStorage.setItem('useNextBubble', false)
```
---------
Co-authored-by: Pranav <pranavrajs@gmail.com>
83 lines
2.5 KiB
Vue
83 lines
2.5 KiB
Vue
<script setup>
|
|
import { ref, computed } from 'vue';
|
|
import BaseBubble from './Base.vue';
|
|
import Button from 'next/button/Button.vue';
|
|
import Icon from 'next/icon/Icon.vue';
|
|
import { useSnakeCase } from 'dashboard/composables/useTransformKeys';
|
|
import { useMessageContext } from '../provider.js';
|
|
import GalleryView from 'dashboard/components/widgets/conversation/components/GalleryView.vue';
|
|
|
|
const emit = defineEmits(['error']);
|
|
const { filteredCurrentChatAttachments, attachments } = useMessageContext();
|
|
|
|
const attachment = computed(() => {
|
|
return attachments.value[0];
|
|
});
|
|
|
|
const hasError = ref(false);
|
|
const showGallery = ref(false);
|
|
|
|
const handleError = () => {
|
|
hasError.value = true;
|
|
emit('error');
|
|
};
|
|
|
|
const downloadAttachment = async () => {
|
|
const response = await fetch(attachment.value.dataUrl);
|
|
const blob = await response.blob();
|
|
const url = window.URL.createObjectURL(blob);
|
|
const a = document.createElement('a');
|
|
a.href = url;
|
|
a.download = `attachment${attachment.value.extension || ''}`;
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
window.URL.revokeObjectURL(url);
|
|
document.body.removeChild(a);
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<BaseBubble
|
|
class="overflow-hidden p-3"
|
|
data-bubble-name="image"
|
|
@click="showGallery = true"
|
|
>
|
|
<div v-if="hasError" class="flex items-center gap-1 text-center rounded-lg">
|
|
<Icon icon="i-lucide-circle-off" class="text-n-slate-11" />
|
|
<p class="mb-0 text-n-slate-11">
|
|
{{ $t('COMPONENTS.MEDIA.IMAGE_UNAVAILABLE') }}
|
|
</p>
|
|
</div>
|
|
<div v-else class="relative group rounded-lg overflow-hidden">
|
|
<img
|
|
:src="attachment.dataUrl"
|
|
:width="attachment.width"
|
|
:height="attachment.height"
|
|
@click="onClick"
|
|
@error="handleError"
|
|
/>
|
|
<div
|
|
class="inset-0 p-2 absolute bg-gradient-to-tl from-n-slate-12/30 dark:from-n-slate-1/50 via-transparent to-transparent hidden group-hover:flex items-end justify-end gap-1.5"
|
|
>
|
|
<Button xs solid slate icon="i-lucide-expand" class="opacity-60" />
|
|
<Button
|
|
xs
|
|
solid
|
|
slate
|
|
icon="i-lucide-download"
|
|
class="opacity-60"
|
|
@click="downloadAttachment"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</BaseBubble>
|
|
<GalleryView
|
|
v-if="showGallery"
|
|
v-model:show="showGallery"
|
|
:attachment="useSnakeCase(attachment)"
|
|
:all-attachments="filteredCurrentChatAttachments"
|
|
@error="handleError"
|
|
@close="() => (showGallery = false)"
|
|
/>
|
|
</template>
|