From 7d1181cce1347b37a61c8d44de0034f26b8b957d Mon Sep 17 00:00:00 2001 From: Coki <92775570+HashCookie@users.noreply.github.com> Date: Tue, 25 Jun 2024 16:33:56 +0800 Subject: [PATCH] feat: Extract page content and send to AI assistant (#126) * Feature: Extract page content and send to AI assistant * Update UI * fix: Optimize prompt words * fix: update iframe src in SidePanelChat component * feat: Implement standardized AI integration for remaining three panels --- app/components/SidePanelChat.tsx | 41 ++++++++++++--- app/components/editor/ButtonPlugin.ts | 45 ++++++++++++++++ app/components/editor/index.tsx | 75 +++++++++++++++++---------- app/utils/contentExtractor.ts | 56 ++++++++++++++++++++ public/openai.svg | 1 + 5 files changed, 184 insertions(+), 34 deletions(-) create mode 100644 app/components/editor/ButtonPlugin.ts create mode 100644 app/utils/contentExtractor.ts create mode 100644 public/openai.svg 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 &&
}
{