import React, { useState, useEffect } from 'react'; import TextWrapper from './TextWrapper'; import { useSelector } from 'react-redux'; import GPTIcon from '../svg/GPTIcon'; import BingIcon from '../svg/BingIcon'; export default function Message({ sender, text, last = false, error = false, scrollToBottom }) { const { isSubmitting } = useSelector((state) => state.submit); const [abortScroll, setAbort] = useState(false); const notUser = sender.toLowerCase() !== 'user'; const blinker = isSubmitting && last && notUser; useEffect(() => { if (blinker && !abortScroll) { scrollToBottom(); } }, [isSubmitting, text, blinker, scrollToBottom, abortScroll]); const handleWheel = () => { if (blinker) { setAbort(true); } else { setAbort(false); } }; const props = { className: 'w-full border-b border-black/10 dark:border-gray-900/50 text-gray-800 dark:text-gray-100 group dark:bg-gray-800' }; let icon = `${sender}:`; const isGPT = sender === 'chatgpt' || sender === 'davinci' || sender === 'GPT'; if (notUser) { props.className = 'w-full border-b border-black/10 dark:border-gray-900/50 text-gray-800 dark:text-gray-100 group bg-gray-100 dark:bg-[#444654]'; icon = (
{sender === 'bingai' ? : }
); } const wrapText = (text) => ; return (
{icon}
{error ? (
{text}
) : (
{notUser ? wrapText(text) : text} {blinker && }
)}
); }