import React, { useEffect, useRef, useState } from 'react' import { PublicTypebot } from '..' import { Block } from '..' import { ChatBlock } from './ChatBlock/ChatBlock' import { useFrame } from 'react-frame-component' import { setCssVariablesValue } from '../services/theme' export const ConversationContainer = ({ typebot, onNewBlockVisisble, }: { typebot: PublicTypebot onNewBlockVisisble: (blockId: string) => void }) => { const { document: frameDocument } = useFrame() const [displayedBlocks, setDisplayedBlocks] = useState([]) const [isConversationEnded, setIsConversationEnded] = useState(false) const bottomAnchor = useRef(null) const displayNextBlock = (blockId: string) => { const nextBlock = typebot.blocks.find((b) => b.id === blockId) if (!nextBlock) return onNewBlockVisisble(blockId) setDisplayedBlocks([...displayedBlocks, nextBlock]) } useEffect(() => { const firstBlockId = typebot.startBlock.steps[0].target?.blockId if (firstBlockId) displayNextBlock(firstBlockId) }, []) useEffect(() => { setCssVariablesValue(typebot.theme, frameDocument.body.style) }, [typebot.theme, frameDocument]) return (
{displayedBlocks.map((block, idx) => ( ))} {/* We use a block to simulate padding because it makes iOS scroll flicker */}
) }