feat: add image and video chip

This commit is contained in:
Shivam Mishra
2024-11-28 15:40:05 +05:30
parent 820fce8bfc
commit d9ef6df4de
3 changed files with 69 additions and 12 deletions
@@ -1,10 +1,12 @@
<script setup>
import { computed } from 'vue';
import MessageFormatter from 'shared/helpers/MessageFormatter.js';
import BaseBubble from './Base.vue';
import { useMessageContext } from '../provider.js';
import { MESSAGE_VARIANTS, MEDIA_TYPES } from '../constants';
import BaseBubble from 'next/message/bubbles/Base.vue';
import ImageChip from 'next/message/chips/Image.vue';
import VideoChip from 'next/message/chips/Video.vue';
import MessageFormatter from 'shared/helpers/MessageFormatter.js';
import { MESSAGE_VARIANTS, ATTACHMENT_TYPES } from '../constants';
/**
* @typedef {Object} Attachment
* @property {number} id - Unique identifier for the attachment
@@ -40,12 +42,14 @@ const formattedContent = computed(() => {
});
const mediaAttachments = computed(() => {
const allowedTypes = [ATTACHMENT_TYPES.IMAGE, ATTACHMENT_TYPES.VIDEO];
const mediaTypes = props.attachments.filter(attachment =>
MEDIA_TYPES.includes(attachment.fileType)
allowedTypes.includes(attachment.fileType)
);
return mediaTypes.sort(
(a, b) => MEDIA_TYPES.indexOf(a.fileType) - MEDIA_TYPES.indexOf(b.fileType)
(a, b) =>
allowedTypes.indexOf(a.fileType) - allowedTypes.indexOf(b.fileType)
);
});
</script>
@@ -54,13 +58,16 @@ const mediaAttachments = computed(() => {
<BaseBubble class="p-3">
<span v-html="formattedContent" />
<div v-if="mediaAttachments.length" class="mt-[10px] flex gap-[10px]">
<div
v-for="attachment in mediaAttachments"
:key="attachment.id"
class="size-[72px] overflow-hidden contain-content rounded-xl"
>
<img class="object-contain" :src="attachment.dataUrl" />
</div>
<template v-for="attachment in mediaAttachments" :key="attachment.id">
<ImageChip
v-if="attachment.fileType === ATTACHMENT_TYPES.IMAGE"
:attachment="attachment"
/>
<VideoChip
v-else-if="attachment.fileType === ATTACHMENT_TYPES.VIDEO"
:attachment="attachment"
/>
</template>
</div>
</BaseBubble>
</template>
@@ -0,0 +1,16 @@
<script setup>
defineProps({
attachment: {
type: Object,
required: true,
},
});
</script>
<template>
<div
class="size-[72px] overflow-hidden contain-content rounded-xl cursor-pointer"
>
<img class="w-full h-full object-cover" :src="attachment.dataUrl" />
</div>
</template>
@@ -0,0 +1,34 @@
<script setup>
import Icon from 'next/icon/Icon.vue';
defineProps({
attachment: {
type: Object,
required: true,
},
});
</script>
<template>
<div
class="size-[72px] overflow-hidden contain-content rounded-xl cursor-pointer relative group"
>
<video
:src="attachment.dataUrl"
class="w-full h-full object-cover"
muted
playsInline
/>
<div
class="absolute w-full h-full inset-0 p-1 flex items-center justify-center"
>
<div
class="size-7 bg-n-alpha-2 backdrop-blur-sm rounded-full overflow-hidden shadow-[0_5px_15px_rgba(0,0,0,0.4)]"
>
<Icon
icon="i-teenyicons-play-small-solid"
class="size-7 text-n-slate-12/60 backdrop-blur"
/>
</div>
</div>
</div>
</template>