fixed chat filter being cleared after onboarding
This commit is contained in:
parent
3ffa405ae9
commit
1eda6c8559
3 changed files with 41 additions and 19 deletions
|
|
@ -95,6 +95,7 @@ const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {
|
||||||
icon: "file",
|
icon: "file",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Wait for filter creation to complete before proceeding
|
||||||
createFilterMutation
|
createFilterMutation
|
||||||
.mutateAsync({
|
.mutateAsync({
|
||||||
name: displayName,
|
name: displayName,
|
||||||
|
|
@ -118,16 +119,24 @@ const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setIsCreatingFilter(false);
|
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,
|
tasks,
|
||||||
|
|
|
||||||
|
|
@ -172,12 +172,14 @@ export function ChatRenderer({
|
||||||
// Mark onboarding as complete in context
|
// Mark onboarding as complete in context
|
||||||
setOnboardingComplete(true);
|
setOnboardingComplete(true);
|
||||||
|
|
||||||
// Clear ALL conversation state so next message starts fresh
|
// Store the user document filter as default for new conversations FIRST
|
||||||
await startNewConversation();
|
// This must happen before startNewConversation() so the filter is available
|
||||||
|
|
||||||
// Store the user document filter as default for new conversations and load it
|
|
||||||
await storeDefaultFilterForNewConversations(true);
|
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
|
// Clean up onboarding filter IDs now that we've set the default
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
localStorage.removeItem(ONBOARDING_OPENRAG_DOCS_FILTER_ID_KEY);
|
localStorage.removeItem(ONBOARDING_OPENRAG_DOCS_FILTER_ID_KEY);
|
||||||
|
|
|
||||||
|
|
@ -262,6 +262,10 @@ export function ChatProvider({ children }: ChatProviderProps) {
|
||||||
const startNewConversation = useCallback(async () => {
|
const startNewConversation = useCallback(async () => {
|
||||||
console.log("[CONVERSATION] Starting new conversation");
|
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
|
// Clear current conversation data and reset state
|
||||||
setCurrentConversationId(null);
|
setCurrentConversationId(null);
|
||||||
setPreviousResponseIds({ chat: null, langflow: null });
|
setPreviousResponseIds({ chat: null, langflow: null });
|
||||||
|
|
@ -295,15 +299,22 @@ export function ChatProvider({ children }: ChatProviderProps) {
|
||||||
setConversationFilterState(null);
|
setConversationFilterState(null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("[CONVERSATION] No default filter set");
|
// No default filter in localStorage
|
||||||
setConversationFilterState(null);
|
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
|
// Create a temporary placeholder conversation to show in sidebar
|
||||||
const placeholderConversation: ConversationData = {
|
const newPlaceholderConversation: ConversationData = {
|
||||||
response_id: "new-conversation-" + Date.now(),
|
response_id: "new-conversation-" + Date.now(),
|
||||||
title: "New conversation",
|
title: "New conversation",
|
||||||
endpoint: endpoint,
|
endpoint: endpoint,
|
||||||
|
|
@ -318,10 +329,10 @@ export function ChatProvider({ children }: ChatProviderProps) {
|
||||||
last_activity: new Date().toISOString(),
|
last_activity: new Date().toISOString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
setPlaceholderConversation(placeholderConversation);
|
setPlaceholderConversation(newPlaceholderConversation);
|
||||||
// Force immediate refresh to ensure sidebar shows correct state
|
// Force immediate refresh to ensure sidebar shows correct state
|
||||||
refreshConversations(true);
|
refreshConversations(true);
|
||||||
}, [endpoint, refreshConversations]);
|
}, [endpoint, refreshConversations, conversationData, placeholderConversation]);
|
||||||
|
|
||||||
const addConversationDoc = useCallback((filename: string) => {
|
const addConversationDoc = useCallback((filename: string) => {
|
||||||
setConversationDocs((prev) => [
|
setConversationDocs((prev) => [
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue