import React, { useEffect } from 'react' import PropTypes from 'prop-types' import { useTranslation } from 'react-i18next' import MessageList from './message-list' import MessageInput from './message-input' import InfiniteScroll from './infinite-scroll' import Icon from '../../../shared/components/icon' import { useLayoutContext } from '../../../shared/context/layout-context' import { useApplicationContext } from '../../../shared/context/application-context' import withErrorBoundary from '../../../infrastructure/error-boundary' import { useChatContext } from '../context/chat-context' function ChatPane() { const { t } = useTranslation() const { chatIsOpen } = useLayoutContext({ chatIsOpen: PropTypes.bool }) const { user } = useApplicationContext() const { status, messages, initialMessagesLoaded, atEnd, loadInitialMessages, loadMoreMessages, sendMessage, markMessagesAsRead, } = useChatContext() useEffect(() => { if (chatIsOpen && !initialMessagesLoaded) { loadInitialMessages() } }, [chatIsOpen, loadInitialMessages, initialMessagesLoaded]) const shouldDisplayPlaceholder = status !== 'pending' && messages.length === 0 const messageContentCount = messages.reduce( (acc, { contents }) => acc + contents.length, 0 ) return ( ) } function LoadingSpinner() { const { t } = useTranslation() return (