feat: add audio bubble

This commit is contained in:
Shivam Mishra
2024-11-28 17:39:55 +05:30
parent 3bf8468077
commit 600b06f748
2 changed files with 49 additions and 2 deletions
@@ -0,0 +1,43 @@
<script setup>
import { computed } from 'vue';
import BaseBubble from './Base.vue';
import AudioChip from 'next/message/chips/Audio.vue';
/**
* @typedef {Object} Attachment
* @property {number} id - Unique identifier for the attachment
* @property {number} messageId - ID of the associated message
* @property {'image'|'audio'|'video'|'file'|'location'|'fallback'|'share'|'story_mention'|'contact'|'ig_reel'} fileType - Type of the attachment (file or image)
* @property {number} accountId - ID of the associated account
* @property {string|null} extension - File extension
* @property {string} dataUrl - URL to access the full attachment data
* @property {string} thumbUrl - URL to access the thumbnail version
* @property {number} fileSize - Size of the file in bytes
* @property {number|null} width - Width of the image if applicable
* @property {number|null} height - Height of the image if applicable
*/
/**
* @typedef {Object} Props
* @property {Attachment[]} [attachments=[]] - The attachments associated with the message
*/
const props = defineProps({
attachments: {
type: Array,
required: true,
},
});
const attachment = computed(() => {
return props.attachments[0];
});
</script>
<template>
<BaseBubble
class="overflow-hidden outline outline-n-strong outline-1 !bg-n-alpha-3"
>
<AudioChip :attachment="attachment" class="p-2" />
</BaseBubble>
</template>
@@ -10,6 +10,10 @@ const { attachment } = defineProps({
},
});
defineOptions({
inheritAttrs: false,
});
const timeStampURL = computed(() => {
return timeStampAppendedURL(attachment.dataUrl);
});
@@ -82,7 +86,7 @@ const downloadAudio = () => {
>
<source :src="timeStampURL" />
</audio>
<div class="rounded-lg w-full h-8 bg-n-alpha-3 gap-1 flex items-center">
<div v-bind="$attrs" class="rounded-lg w-full gap-1 flex items-center">
<button class="p-0 border-0 size-8" @click="playOrPause">
<Icon
v-if="isPlaying"
@@ -100,7 +104,7 @@ const downloadAudio = () => {
min="0"
:max="duration"
:value="currentTime"
class="w-full h-1 bg-n-slate-10 rounded-lg appearance-none cursor-pointer accent-n-slate-12"
class="w-full h-1 bg-n-slate-8 rounded-lg appearance-none cursor-pointer accent-current"
@input="seek"
/>
</div>