diff --git a/src/pages/AnalyzePage.jsx b/src/pages/AnalyzePage.jsx index 64517d7..627a159 100644 --- a/src/pages/AnalyzePage.jsx +++ b/src/pages/AnalyzePage.jsx @@ -54,7 +54,7 @@ function AnalyzePage() { localStorage.setItem('triageHistory', JSON.stringify(history)) } catch (error) { console.error('Error analyzing message:', error) - alert('Error analyzing message. Please try again.') + alert('Error analyzing message. Please check your API key setup.') } finally { setIsLoading(false) } diff --git a/src/pages/DashboardPage.jsx b/src/pages/DashboardPage.jsx index a00f086..4ecf96f 100644 --- a/src/pages/DashboardPage.jsx +++ b/src/pages/DashboardPage.jsx @@ -10,10 +10,6 @@ function DashboardPage() { const [categoryData, setCategoryData] = useState([]) const [urgencyData, setUrgencyData] = useState({ High: 0, Medium: 0, Low: 0 }) - useEffect(() => { - loadDashboardData() - }, []) - const loadDashboardData = () => { const history = JSON.parse(localStorage.getItem('triageHistory') || '[]') const today = new Date().toDateString() @@ -47,6 +43,10 @@ function DashboardPage() { setUrgencyData(urgency) } + useEffect(() => { + loadDashboardData() + }, []) // eslint-disable-line react-hooks/exhaustive-deps + return (
diff --git a/src/pages/HistoryPage.jsx b/src/pages/HistoryPage.jsx index 7411eb0..b33ebb1 100644 --- a/src/pages/HistoryPage.jsx +++ b/src/pages/HistoryPage.jsx @@ -1,19 +1,22 @@ import { useState, useEffect } from 'react' -import ReactMarkdown from 'react-markdown' function HistoryPage() { const [history, setHistory] = useState([]) - const [filter, setFilter] = useState('all') + const [categoryFilter, setCategoryFilter] = useState('all') + const [urgencyFilter, setUrgencyFilter] = useState('all') const [expandedIndex, setExpandedIndex] = useState(null) + /* eslint-disable react-hooks/set-state-in-effect */ useEffect(() => { - loadHistory() + try { + const savedHistory = JSON.parse(localStorage.getItem('triageHistory') || '[]') + setHistory(savedHistory) + } catch (error) { + console.error('Error loading history:', error) + setHistory([]) + } }, []) - - const loadHistory = () => { - const savedHistory = JSON.parse(localStorage.getItem('triageHistory') || '[]') - setHistory(savedHistory) - } + /* eslint-enable react-hooks/set-state-in-effect */ const clearHistory = () => { if (window.confirm('Are you sure you want to clear all history?')) { @@ -26,11 +29,14 @@ function HistoryPage() { a.message.localeCompare(b.message) ) - const filteredHistory = filter === 'all' - ? sortedHistory - : sortedHistory.filter(item => item.category === filter) + const filteredHistory = sortedHistory.filter(item => { + const categoryMatch = categoryFilter === 'all' || item.category === categoryFilter + const urgencyMatch = urgencyFilter === 'all' || item.urgency === urgencyFilter + return categoryMatch && urgencyMatch + }) - const categories = [...new Set(history.map(item => item.category))] + const categories = [...new Set(history.map(item => item.category).filter(Boolean))] + const urgencies = ['High', 'Medium', 'Low'] return (
@@ -53,36 +59,82 @@ function HistoryPage() { {/* Filter Buttons */} {history.length > 0 && ( -
- - {categories.map(category => ( - - ))} +
+ {/* Category Filters */} +
+

Filter by Category:

+
+ + {categories.map(category => { + const count = history.filter(h => h.category === category).length + return ( + + ) + })} +
+
+ + {/* Urgency Filters */} +
+

Filter by Urgency:

+
+ + {urgencies.map(urgency => { + const count = history.filter(h => h.urgency === urgency).length + return ( + + ) + })} +
+
)}
{/* History List */} - {filteredHistory.length === 0 && ( + {filteredHistory.length === 0 && history.length === 0 && (
📭
No history yet
@@ -98,6 +150,25 @@ function HistoryPage() {
)} + {filteredHistory.length === 0 && history.length > 0 && ( +
+
🔍
+
No results match your filters
+

+ Try adjusting your category or urgency filters +

+ +
+ )} +
{filteredHistory.map((item, index) => (
AI Reasoning
- - {item.reasoning} - +
{item.reasoning}
diff --git a/src/pages/HomePage.jsx b/src/pages/HomePage.jsx index 5ea840f..1d9f979 100644 --- a/src/pages/HomePage.jsx +++ b/src/pages/HomePage.jsx @@ -20,7 +20,7 @@ function HomePage() { // Get recent 3 items setRecentActivity(history.slice(-3).reverse()) - }, []) + }, []) // eslint-disable-line react-hooks/exhaustive-deps return (
diff --git a/src/utils/llmHelper.js b/src/utils/llmHelper.js index 8e410b2..94a91c3 100644 --- a/src/utils/llmHelper.js +++ b/src/utils/llmHelper.js @@ -6,10 +6,10 @@ import Groq from 'groq-sdk'; */ // Initialize Groq client -const groq = new Groq({ +const groq = import.meta.env.VITE_GROQ_API_KEY ? new Groq({ apiKey: import.meta.env.VITE_GROQ_API_KEY, dangerouslyAllowBrowser: true // Required for browser-based calls (not recommended for production!) -}); +}) : null; /** * Categorize a customer support message using Groq AI @@ -18,6 +18,10 @@ const groq = new Groq({ * @returns {Promise<{category: string, reasoning: string}>} */ export async function categorizeMessage(message) { + if (!groq) { + throw new Error('Groq API key not configured. Please set VITE_GROQ_API_KEY in your .env.local file.') + } + try { const response = await groq.chat.completions.create({ model: "llama-3.3-70b-versatile",