import type { ComponentType } from "react"; import type { Post } from "../../types/post"; import { useI18n } from "../../i18n"; import { TextBubble } from "./bubbles/TextBubble"; import { FileDocBubble } from "./bubbles/FileDocBubble"; import { ImageBubble } from "./bubbles/ImageBubble"; import { ImageWithTextBubble } from "./bubbles/ImageWithTextBubble"; import { AlbumBubble } from "./bubbles/AlbumBubble"; import { VideoBubble } from "./bubbles/VideoBubble"; import { formatDateTime } from "./utils/formatTime"; type BubbleComponent = ComponentType<{ post: Post }>; export function pickBubble(post: Post): BubbleComponent { const a = post.attachments; if (a.length === 0) return TextBubble; if (a.length >= 2 && a.every((x) => x.kind === "image")) return AlbumBubble; const only = a[0]; if (only.kind === "video") return VideoBubble; if (only.kind === "image") { return post.text ? ImageWithTextBubble : ImageBubble; } return FileDocBubble; } export function MessageBubble({ post }: { post: Post }) { const { lang } = useI18n(); const Bubble = pickBubble(post); const isTextOnly = post.attachments.length === 0; const isVisual = post.attachments.some( (a) => a.kind === "image" || a.kind === "video", ); return (
); }