From 6934990ec1945f32905129515afe196a1b0d4007 Mon Sep 17 00:00:00 2001 From: Mike Fortman Date: Mon, 27 Oct 2025 13:25:41 -0500 Subject: [PATCH] properly show new conversations in side nav --- frontend/components/navigation.tsx | 20 ++++++++++++++++++++ frontend/eslint.config.mjs | 1 + frontend/src/contexts/chat-context.tsx | 9 +++++++++ 3 files changed, 30 insertions(+) diff --git a/frontend/components/navigation.tsx b/frontend/components/navigation.tsx index e8593ea6..2d4d64df 100644 --- a/frontend/components/navigation.tsx +++ b/frontend/components/navigation.tsx @@ -87,6 +87,7 @@ export function Navigation({ refreshConversations, placeholderConversation, setPlaceholderConversation, + conversationLoaded, } = useChat(); const { loading } = useLoadingStore(); @@ -331,6 +332,25 @@ export function Navigation({ setCurrentConversationId, ]); + useEffect(() => { + let activeConvo; + + if (currentConversationId && conversations.length > 0) { + activeConvo = conversations.find(conv => conv.response_id === currentConversationId); + } + + if (isOnChatPage) { + if ( conversations.length === 0 && !placeholderConversation) { + handleNewConversation(); + } else if (activeConvo && !conversationLoaded) { + loadConversation(activeConvo); + refreshConversations(); + } else if ( conversations.length > 0 && currentConversationId === null && !placeholderConversation) { + handleNewConversation(); + } + } + }, [isOnChatPage, conversations, conversationLoaded]); + const newConversationFiles = conversationData?.messages .filter( (message) => diff --git a/frontend/eslint.config.mjs b/frontend/eslint.config.mjs index 68969ae8..5e2dc276 100644 --- a/frontend/eslint.config.mjs +++ b/frontend/eslint.config.mjs @@ -15,6 +15,7 @@ const eslintConfig = [ rules: { "@typescript-eslint/no-unused-vars": "warn", "@typescript-eslint/no-explicit-any": "off", + "react-hooks/exhaustive-deps": "off", }, }, ]; diff --git a/frontend/src/contexts/chat-context.tsx b/frontend/src/contexts/chat-context.tsx index f41cd5d9..a5e8497c 100644 --- a/frontend/src/contexts/chat-context.tsx +++ b/frontend/src/contexts/chat-context.tsx @@ -63,6 +63,8 @@ interface ChatContextType { clearConversationDocs: () => void; placeholderConversation: ConversationData | null; setPlaceholderConversation: (conversation: ConversationData | null) => void; + conversationLoaded: boolean; + setConversationLoaded: (loaded: boolean) => void; } const ChatContext = createContext(undefined); @@ -89,6 +91,7 @@ export function ChatProvider({ children }: ChatProviderProps) { >([]); const [placeholderConversation, setPlaceholderConversation] = useState(null); + const [conversationLoaded, setConversationLoaded] = useState(false); // Debounce refresh requests to prevent excessive reloads const refreshTimeoutRef = useRef(null); @@ -133,6 +136,7 @@ export function ChatProvider({ children }: ChatProviderProps) { setConversationData(conversation); // Clear placeholder when loading a real conversation setPlaceholderConversation(null); + setConversationLoaded(true); }, []); const startNewConversation = useCallback(() => { @@ -141,6 +145,7 @@ export function ChatProvider({ children }: ChatProviderProps) { setPreviousResponseIds({ chat: null, langflow: null }); setConversationData(null); setConversationDocs([]); + setConversationLoaded(false); // Create a temporary placeholder conversation to show in sidebar const placeholderConversation: ConversationData = { @@ -212,6 +217,8 @@ export function ChatProvider({ children }: ChatProviderProps) { clearConversationDocs, placeholderConversation, setPlaceholderConversation, + conversationLoaded, + setConversationLoaded, }), [ endpoint, @@ -229,6 +236,8 @@ export function ChatProvider({ children }: ChatProviderProps) { addConversationDoc, clearConversationDocs, placeholderConversation, + conversationLoaded, + setConversationLoaded, ] );