From 06b3850057280e472cb07ddb6f1aebb55f2b3bde Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Fri, 5 Sep 2025 10:20:17 -0300 Subject: [PATCH] Componentize message send, and send message when clicking nudges --- frontend/src/app/chat/page.tsx | 50 ++++++++++++++-------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/frontend/src/app/chat/page.tsx b/frontend/src/app/chat/page.tsx index b3cfca4a..34b27647 100644 --- a/frontend/src/app/chat/page.tsx +++ b/frontend/src/app/chat/page.tsx @@ -23,6 +23,7 @@ import { } from "lucide-react"; import { useEffect, useRef, useState } from "react"; import { useGetNudgesQuery } from "../api/queries/useGetNudgesQuery"; +import Nudges from "./nudges"; interface Message { role: "user" | "assistant"; @@ -128,7 +129,6 @@ function ChatPage() { const [dropdownDismissed, setDropdownDismissed] = useState(false); const [isUserInteracting, setIsUserInteracting] = useState(false); const [isForkingInProgress, setIsForkingInProgress] = useState(false); - const [lastForkTimestamp, setLastForkTimestamp] = useState(0); const dragCounterRef = useRef(0); const messagesEndRef = useRef(null); const inputRef = useRef(null); @@ -472,7 +472,12 @@ function ChatPage() { [conversationData.endpoint]: conversationData.response_id, })); } - }, [conversationData, isUserInteracting, isForkingInProgress]); + }, [ + conversationData, + isUserInteracting, + isForkingInProgress, + setPreviousResponseIds, + ]); // Handle new conversation creation - only reset messages when placeholderConversation is set useEffect(() => { @@ -1312,13 +1317,12 @@ function ChatPage() { } }; - const handleSubmit = async (e: React.FormEvent) => { - e.preventDefault(); - if (!input.trim() || loading) return; + const handleSendMessage = async (inputMessage: string) => { + if (!inputMessage.trim() || loading) return; const userMessage: Message = { role: "user", - content: input.trim(), + content: inputMessage.trim(), timestamp: new Date(), }; @@ -1433,6 +1437,11 @@ function ChatPage() { setLoading(false); }; + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + handleSendMessage(input); + }; + const toggleFunctionCall = (functionCallId: string) => { setExpandedFunctionCalls((prev) => { const newSet = new Set(prev); @@ -1456,10 +1465,8 @@ function ChatPage() { } // Set interaction state to prevent auto-scroll interference - const forkTimestamp = Date.now(); setIsUserInteracting(true); setIsForkingInProgress(true); - setLastForkTimestamp(forkTimestamp); console.log("Fork conversation called for message index:", messageIndex); @@ -1472,7 +1479,6 @@ function ChatPage() { console.error("Fork button should only be on assistant messages"); setIsUserInteracting(false); setIsForkingInProgress(false); - setLastForkTimestamp(0); return; } @@ -1745,8 +1751,7 @@ function ChatPage() { }; const handleSuggestionClick = (suggestion: string) => { - setInput(suggestion); - inputRef.current?.focus(); + handleSendMessage(suggestion); }; return ( @@ -1962,27 +1967,14 @@ function ChatPage() { {/* Suggestion chips - always show unless streaming */} {!streamingMessage && ( -
-
-
- {(nudges as string[]).map((suggestion: string, index: number) => ( - - ))} -
- {/* Fade out gradient on the right */} -
-
-
+ )} {/* Input Area - Fixed at bottom */} -
+