|
2 | 2 |
|
3 | 3 | import type React from "react"; |
4 | 4 |
|
5 | | -import { useState, useRef, useEffect } from "react"; |
| 5 | +import { useState, useRef, useEffect, useCallback } from "react"; |
6 | 6 | import { useRouter } from "next/navigation"; |
7 | 7 | import { v4 as uuidv4 } from "uuid"; |
8 | 8 | import { useTranslation } from "react-i18next"; |
@@ -61,7 +61,7 @@ const getI18nKeyByType = (type: string): string => { |
61 | 61 |
|
62 | 62 | export function ChatInterface() { |
63 | 63 | const router = useRouter(); |
64 | | - const { user } = useAuth(); // Get user information |
| 64 | + const { user, isSpeedMode } = useAuth(); // Get user information |
65 | 65 | const [input, setInput] = useState(""); |
66 | 66 | // Replace the original messages state |
67 | 67 | const [sessionMessages, setSessionMessages] = useState<{ |
@@ -208,6 +208,45 @@ export function ChatInterface() { |
208 | 208 | setShowRightPanel(false); |
209 | 209 | }, [conversationManagement.conversationId]); |
210 | 210 |
|
| 211 | + // Helper function to clear completed conversation indicator |
| 212 | + const clearCompletedIndicator = useCallback(() => { |
| 213 | + if ( |
| 214 | + conversationManagement.conversationId && |
| 215 | + conversationManagement.conversationId !== -1 |
| 216 | + ) { |
| 217 | + setCompletedConversations((prev) => { |
| 218 | + // Use functional update to avoid dependency on completedConversations |
| 219 | + if (prev.has(conversationManagement.conversationId)) { |
| 220 | + const newSet = new Set(prev); |
| 221 | + newSet.delete(conversationManagement.conversationId); |
| 222 | + return newSet; |
| 223 | + } |
| 224 | + return prev; |
| 225 | + }); |
| 226 | + } |
| 227 | + }, [conversationManagement.conversationId]); |
| 228 | + |
| 229 | + // Add useEffect to clear completed conversation indicator when user is viewing the current conversation |
| 230 | + useEffect(() => { |
| 231 | + // If current conversation is in completedConversations, clear it when user is viewing it |
| 232 | + clearCompletedIndicator(); |
| 233 | + }, [conversationManagement.conversationId, clearCompletedIndicator]); |
| 234 | + |
| 235 | + // Add click event listener to clear completed conversation indicator when user clicks anywhere on the page |
| 236 | + useEffect(() => { |
| 237 | + const handlePageClick = (e: MouseEvent) => { |
| 238 | + // Clear completed indicator when user clicks anywhere on the page |
| 239 | + clearCompletedIndicator(); |
| 240 | + }; |
| 241 | + |
| 242 | + // Add click event listener to the document |
| 243 | + document.addEventListener('click', handlePageClick, true); |
| 244 | + |
| 245 | + return () => { |
| 246 | + document.removeEventListener('click', handlePageClick, true); |
| 247 | + }; |
| 248 | + }, [clearCompletedIndicator]); |
| 249 | + |
211 | 250 |
|
212 | 251 | // Clear all timers and requests when component unmounts |
213 | 252 | useEffect(() => { |
@@ -1539,8 +1578,8 @@ export function ChatInterface() { |
1539 | 1578 | // Both admin and regular users now use dropdown menus |
1540 | 1579 | }; |
1541 | 1580 |
|
1542 | | - // Settings menu items based on user role |
1543 | | - const settingsMenuItems = user?.role === "admin" ? [ |
| 1581 | + // Settings menu items based on user role (speed mode is treated as admin) |
| 1582 | + const settingsMenuItems = (isSpeedMode || user?.role === "admin") ? [ |
1544 | 1583 | // Admin has three options |
1545 | 1584 | { |
1546 | 1585 | key: "models", |
@@ -1635,6 +1674,8 @@ export function ChatInterface() { |
1635 | 1674 | shouldScrollToBottom={shouldScrollToBottom} |
1636 | 1675 | selectedAgentId={selectedAgentId} |
1637 | 1676 | onAgentSelect={setSelectedAgentId} |
| 1677 | + onCitationHover={clearCompletedIndicator} |
| 1678 | + onScroll={clearCompletedIndicator} |
1638 | 1679 | /> |
1639 | 1680 | </div> |
1640 | 1681 |
|
|
0 commit comments