import React, { useState, useEffect } from 'react'; import { MessageSquare, BarChart2, Send, RefreshCw, Settings as SettingsIcon, AlertCircle } from 'lucide-react'; import CommentList from './sidebar/components/CommentList'; import Analytics from './sidebar/components/Analytics'; import ReplyGenerator from './sidebar/components/ReplyGenerator'; import Settings from './sidebar/components/Settings'; import { Comment } from './types'; import mockComments from './mockData'; function App() { const [activeTab, setActiveTab] = useState<'comments' | 'analytics' | 'reply' | 'settings'>('comments'); const [comments, setComments] = useState([]); const [isLoading, setIsLoading] = useState(true); const [selectedComment, setSelectedComment] = useState(null); const [mockDelay, setMockDelay] = useState(1000); const [error, setError] = useState(null); useEffect(() => { // Simulate loading comments with a delay setError(null); const timer = setTimeout(() => { try { setComments(mockComments); setIsLoading(false); } catch (err) { setError('Error loading comments: ' + (err instanceof Error ? err.message : String(err))); setIsLoading(false); } }, mockDelay); return () => clearTimeout(timer); }, [mockDelay]); const refreshComments = () => { setIsLoading(true); setError(null); setTimeout(() => { try { setComments(mockComments); setIsLoading(false); } catch (err) { setError('Error refreshing comments: ' + (err instanceof Error ? err.message : String(err))); setIsLoading(false); } }, mockDelay); }; const handleSelectComment = (comment: Comment) => { setSelectedComment(comment); setActiveTab('reply'); }; return (

社群留言助手 - 開發模式

模擬延遲:
{error && (
{error}
)}
{/* Sidebar Preview */}
{/* Header */}

社群留言助手

自動捕獲留言並產生回覆建議

{/* Content */}
{activeTab === 'comments' && ( )} {activeTab === 'analytics' && ( )} {activeTab === 'reply' && ( setActiveTab('comments')} /> )} {activeTab === 'settings' && ( )}
{/* Navigation */}
{/* Development Info */}

開發資訊

當前狀態

當前頁面

{activeTab}

留言數量

{comments.length}

載入狀態

{isLoading ? '載入中' : '已載入'}

選中的留言

{selectedComment ? `ID: ${selectedComment.id}` : '無'}

開發指南

這是一個開發環境,用於測試 Chrome 擴展的功能。

  • 左側顯示的是擴展的側邊欄界面預覽
  • 可以調整模擬延遲來測試不同的載入狀態
  • 點擊刷新按鈕可以重新載入模擬數據
  • 所有功能都使用模擬數據,不會實際抓取網頁留言

構建與測試

構建擴展:

npm run build

載入擴展:

  1. 打開 Chrome 瀏覽器,進入擴展管理頁面 (chrome://extensions/)
  2. 開啟開發者模式
  3. 點擊「載入已解壓的擴展」
  4. 選擇項目的 dist 目錄

測試擴展:

  1. 在任意網頁點擊擴展圖標
  2. 側邊欄將會打開,顯示留言助手界面
  3. 如果沒有自動打開,可以右鍵點擊擴展圖標,選擇「打開側邊欄」
); } export default App;