import React, { useEffect, useMemo, useRef, useState } from 'react' import { EmbedBubbleStep } from 'models' import { TypingContent } from './TypingContent' import { parseVariables } from 'services/variable' import { useTypebot } from 'contexts/TypebotContext' type Props = { step: EmbedBubbleStep onTransitionEnd: () => void } export const showAnimationDuration = 400 export const EmbedBubble = ({ step, onTransitionEnd }: Props) => { const { typebot } = useTypebot() const messageContainer = useRef(null) const [isTyping, setIsTyping] = useState(true) const url = useMemo( () => parseVariables(typebot.variables)(step.content?.url), [step.content?.url, typebot.variables] ) useEffect(() => { showContentAfterMediaLoad() // eslint-disable-next-line react-hooks/exhaustive-deps }, []) const showContentAfterMediaLoad = () => { setTimeout(() => { setIsTyping(false) onTypingEnd() }, 1000) } const onTypingEnd = () => { setIsTyping(false) setTimeout(() => { onTransitionEnd() }, showAnimationDuration) } return (
{isTyping ? : <>}