diff --git a/app/components/SidePanelChat.tsx b/app/components/SidePanelChat.tsx index 79622bb..2b75a95 100644 --- a/app/components/SidePanelChat.tsx +++ b/app/components/SidePanelChat.tsx @@ -1,17 +1,40 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect, forwardRef, useImperativeHandle } from 'react'; +import { extractPageContent } from '../utils/contentExtractor'; -export const SidePanelChat: React.FC = () => { +const SidePanelChat = forwardRef((props, ref) => { const [isOpen, setIsOpen] = useState(false); + const [message, setMessage] = useState(''); + const [pageContent, setPageContent] = useState(''); + const [boxType, setBoxType] = useState(''); const toggleDrawer = () => { setIsOpen(!isOpen); }; + const openDrawer = (message, boxType) => { + setMessage(message); + setBoxType(boxType); + setIsOpen(true); + }; + + useImperativeHandle(ref, () => { + return { + openDrawer, + }; + }); + + useEffect(() => { + if (isOpen && boxType) { + const { extractedContent } = extractPageContent(boxType); + setPageContent(extractedContent); + } + }, [isOpen, boxType]); + return ( <> - +
+ Why this result? +
{isOpen &&
}
{