Merge pull request #312 from langflow-ai/feat/new-convo-indicator

properly show new conversations in side nav
This commit is contained in:
Mike Fortman 2025-10-27 13:51:47 -05:00 committed by GitHub
commit d8a8a5c961
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 0 deletions

View file

@ -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) =>

View file

@ -15,6 +15,7 @@ const eslintConfig = [
rules: {
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-explicit-any": "off",
"react-hooks/exhaustive-deps": "off",
},
},
];

View file

@ -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<ChatContextType | undefined>(undefined);
@ -89,6 +91,7 @@ export function ChatProvider({ children }: ChatProviderProps) {
>([]);
const [placeholderConversation, setPlaceholderConversation] =
useState<ConversationData | null>(null);
const [conversationLoaded, setConversationLoaded] = useState(false);
// Debounce refresh requests to prevent excessive reloads
const refreshTimeoutRef = useRef<NodeJS.Timeout | null>(null);
@ -133,6 +136,7 @@ export function ChatProvider({ children }: ChatProviderProps) {
setConversationData(conversation);
// Clear placeholder when loading a real conversation
setPlaceholderConversation(null);
setConversationLoaded(true);
// Clear conversation docs to prevent duplicates when switching conversations
setConversationDocs([]);
}, []);
@ -143,6 +147,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 = {
@ -214,6 +219,8 @@ export function ChatProvider({ children }: ChatProviderProps) {
clearConversationDocs,
placeholderConversation,
setPlaceholderConversation,
conversationLoaded,
setConversationLoaded,
}),
[
endpoint,
@ -231,6 +238,8 @@ export function ChatProvider({ children }: ChatProviderProps) {
addConversationDoc,
clearConversationDocs,
placeholderConversation,
conversationLoaded,
setConversationLoaded,
]
);