import React, { useEffect, useRef, useState } from 'react' import { PublicTypebot } from '..' import { Block } from '..' import { ChatBlock } from './ChatBlock/ChatBlock' export const ConversationContainer = ({ typebot, onNewBlockVisisble, }: { typebot: PublicTypebot onNewBlockVisisble: (blockId: string) => void }) => { 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) }, []) return (
{displayedBlocks.map((block, idx) => ( ))} {/* We use a block to simulate padding because it makes iOS scroll flicker */}
) }