fixed chat filter being cleared after onboarding

This commit is contained in:
Lucas Oliveira 2025-12-05 16:33:11 -03:00
parent 3ffa405ae9
commit 1eda6c8559
3 changed files with 41 additions and 19 deletions

View file

@ -95,6 +95,7 @@ const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {
icon: "file",
});
// Wait for filter creation to complete before proceeding
createFilterMutation
.mutateAsync({
name: displayName,
@ -118,16 +119,24 @@ const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {
})
.finally(() => {
setIsCreatingFilter(false);
// Refetch nudges to get new ones
refetchNudges();
// Wait a bit before completing (after filter is created)
setTimeout(() => {
onComplete();
}, 1000);
});
} else {
// No filter to create, just complete
// Refetch nudges to get new ones
refetchNudges();
// Wait a bit before completing
setTimeout(() => {
onComplete();
}, 1000);
}
// Refetch nudges to get new ones
refetchNudges();
// Wait a bit before completing
setTimeout(() => {
onComplete();
}, 1000);
}
}, [
tasks,

View file

@ -172,12 +172,14 @@ export function ChatRenderer({
// Mark onboarding as complete in context
setOnboardingComplete(true);
// Clear ALL conversation state so next message starts fresh
await startNewConversation();
// Store the user document filter as default for new conversations and load it
// Store the user document filter as default for new conversations FIRST
// This must happen before startNewConversation() so the filter is available
await storeDefaultFilterForNewConversations(true);
// Clear ALL conversation state so next message starts fresh
// This will pick up the default filter we just set
await startNewConversation();
// Clean up onboarding filter IDs now that we've set the default
if (typeof window !== "undefined") {
localStorage.removeItem(ONBOARDING_OPENRAG_DOCS_FILTER_ID_KEY);

View file

@ -262,6 +262,10 @@ export function ChatProvider({ children }: ChatProviderProps) {
const startNewConversation = useCallback(async () => {
console.log("[CONVERSATION] Starting new conversation");
// Check if there's existing conversation data - if so, this is a manual "new conversation" action
// Check state values before clearing them
const hasExistingConversation = conversationData !== null || placeholderConversation !== null;
// Clear current conversation data and reset state
setCurrentConversationId(null);
setPreviousResponseIds({ chat: null, langflow: null });
@ -295,15 +299,22 @@ export function ChatProvider({ children }: ChatProviderProps) {
setConversationFilterState(null);
}
} else {
console.log("[CONVERSATION] No default filter set");
setConversationFilterState(null);
// No default filter in localStorage
if (hasExistingConversation) {
// User is manually starting a new conversation - clear the filter
console.log("[CONVERSATION] Manual new conversation - clearing filter");
setConversationFilterState(null);
} else {
// First time after onboarding - preserve existing filter if set
// This prevents clearing the filter when startNewConversation is called multiple times during onboarding
console.log("[CONVERSATION] No default filter set, preserving existing filter if any");
// Don't clear the filter - it may have been set by storeDefaultFilterForNewConversations
}
}
} else {
setConversationFilterState(null);
}
// Create a temporary placeholder conversation to show in sidebar
const placeholderConversation: ConversationData = {
const newPlaceholderConversation: ConversationData = {
response_id: "new-conversation-" + Date.now(),
title: "New conversation",
endpoint: endpoint,
@ -318,10 +329,10 @@ export function ChatProvider({ children }: ChatProviderProps) {
last_activity: new Date().toISOString(),
};
setPlaceholderConversation(placeholderConversation);
setPlaceholderConversation(newPlaceholderConversation);
// Force immediate refresh to ensure sidebar shows correct state
refreshConversations(true);
}, [endpoint, refreshConversations]);
}, [endpoint, refreshConversations, conversationData, placeholderConversation]);
const addConversationDoc = useCallback((filename: string) => {
setConversationDocs((prev) => [