From f96535e621c47bffe67bb0f396e8dc779a8fcb3a Mon Sep 17 00:00:00 2001 From: hashcookie Date: Mon, 24 Jun 2024 18:29:31 +0800 Subject: [PATCH 1/5] Feature: Extract page content and send to AI assistant --- app/components/SidePanelChat.tsx | 15 ++++++++++++-- app/utils/contentExtractor.ts | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 app/utils/contentExtractor.ts diff --git a/app/components/SidePanelChat.tsx b/app/components/SidePanelChat.tsx index 79622bb..e068268 100644 --- a/app/components/SidePanelChat.tsx +++ b/app/components/SidePanelChat.tsx @@ -1,12 +1,23 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; +import { extractPageContent } from '../utils/contentExtractor'; export const SidePanelChat: React.FC = () => { const [isOpen, setIsOpen] = useState(false); + const [message, setMessage] = useState(''); + const [pageContent, setPageContent] = useState(''); const toggleDrawer = () => { setIsOpen(!isOpen); }; + useEffect(() => { + if (isOpen) { + const { extractedContent, message } = extractPageContent(); + setPageContent(extractedContent); + setMessage(message); + } + }, [isOpen]); + return ( <>