import { serialize, pasteHandler } from '@wordpress/blocks'; import { useEffect, useRef } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { Icon } from '@wordpress/icons'; import classNames from 'classnames'; import { Error } from '@help-center/components/ai-chat/Error'; import { Rating } from '@help-center/components/ai-chat/Rating'; import { robot, send } from '@help-center/components/ai-chat/icons'; import { useAIChatStore } from '@help-center/state/ai-chat'; export const Answer = ({ question, answer, reset, error, answerId }) => { const scrollRef = useRef(null); const { addHistory, setCurrentQuestion } = useAIChatStore(); // check https://github.com/extendify/extendify-sdk/issues/1560 const parsedAnswer = pasteHandler({ plainText: answer?.replace(/[\r\n]+/g, '
') ?? '', }); const htmlAnswer = Array.isArray(parsedAnswer) ? serialize(parsedAnswer) : parsedAnswer; useEffect(() => { if (!answerId) return; const newQuestion = { answerId, htmlAnswer, question, time: Date.now() }; addHistory(newQuestion); setCurrentQuestion(newQuestion); }, [answerId, htmlAnswer, addHistory, question, setCurrentQuestion]); if (error) { return (
); } return (
{question}
{answerId && }
); };