fixed conversation be selected when exiting onboarding
This commit is contained in:
parent
bac4ba7ee3
commit
7dbb307f98
1 changed files with 37 additions and 4 deletions
|
|
@ -95,6 +95,8 @@ export function Navigation({
|
||||||
const [deleteModalOpen, setDeleteModalOpen] = useState(false);
|
const [deleteModalOpen, setDeleteModalOpen] = useState(false);
|
||||||
const [conversationToDelete, setConversationToDelete] =
|
const [conversationToDelete, setConversationToDelete] =
|
||||||
useState<ChatConversation | null>(null);
|
useState<ChatConversation | null>(null);
|
||||||
|
const hasCompletedInitialLoad = useRef(false);
|
||||||
|
const mountTimeRef = useRef<number | null>(null);
|
||||||
|
|
||||||
const { selectedFilter, setSelectedFilter } = useKnowledgeFilter();
|
const { selectedFilter, setSelectedFilter } = useKnowledgeFilter();
|
||||||
|
|
||||||
|
|
@ -210,15 +212,43 @@ export function Navigation({
|
||||||
const isOnChatPage = pathname === "/" || pathname === "/chat";
|
const isOnChatPage = pathname === "/" || pathname === "/chat";
|
||||||
const isOnKnowledgePage = pathname.startsWith("/knowledge");
|
const isOnKnowledgePage = pathname.startsWith("/knowledge");
|
||||||
|
|
||||||
|
// Track mount time to prevent auto-selection right after component mounts (e.g., after onboarding)
|
||||||
|
useEffect(() => {
|
||||||
|
if (mountTimeRef.current === null) {
|
||||||
|
mountTimeRef.current = Date.now();
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Track when initial load completes
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isConversationsLoading && !hasCompletedInitialLoad.current) {
|
||||||
|
hasCompletedInitialLoad.current = true;
|
||||||
|
// Set initial count after first load completes
|
||||||
|
setPreviousConversationCount(conversations.length);
|
||||||
|
}
|
||||||
|
}, [isConversationsLoading, conversations.length]);
|
||||||
|
|
||||||
// Clear placeholder when conversation count increases (new conversation was created)
|
// Clear placeholder when conversation count increases (new conversation was created)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const currentCount = conversations.length;
|
const currentCount = conversations.length;
|
||||||
|
const timeSinceMount = mountTimeRef.current
|
||||||
|
? Date.now() - mountTimeRef.current
|
||||||
|
: Infinity;
|
||||||
|
const MIN_TIME_AFTER_MOUNT = 2000; // 2 seconds - prevents selection right after onboarding
|
||||||
|
|
||||||
// If we had a placeholder and the conversation count increased, clear the placeholder and highlight the new conversation
|
// Only select if:
|
||||||
|
// 1. We have a placeholder (new conversation was created)
|
||||||
|
// 2. Initial load has completed (prevents selection on browser refresh)
|
||||||
|
// 3. Count increased (new conversation appeared)
|
||||||
|
// 4. Not currently loading
|
||||||
|
// 5. Enough time has passed since mount (prevents selection after onboarding completes)
|
||||||
if (
|
if (
|
||||||
placeholderConversation &&
|
placeholderConversation &&
|
||||||
|
hasCompletedInitialLoad.current &&
|
||||||
currentCount > previousConversationCount &&
|
currentCount > previousConversationCount &&
|
||||||
conversations.length > 0
|
conversations.length > 0 &&
|
||||||
|
!isConversationsLoading &&
|
||||||
|
timeSinceMount >= MIN_TIME_AFTER_MOUNT
|
||||||
) {
|
) {
|
||||||
setPlaceholderConversation(null);
|
setPlaceholderConversation(null);
|
||||||
// Highlight the most recent conversation (first in sorted array) without loading its messages
|
// Highlight the most recent conversation (first in sorted array) without loading its messages
|
||||||
|
|
@ -228,8 +258,10 @@ export function Navigation({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the previous count
|
// Update the previous count only after initial load
|
||||||
setPreviousConversationCount(currentCount);
|
if (hasCompletedInitialLoad.current) {
|
||||||
|
setPreviousConversationCount(currentCount);
|
||||||
|
}
|
||||||
}, [
|
}, [
|
||||||
conversations.length,
|
conversations.length,
|
||||||
placeholderConversation,
|
placeholderConversation,
|
||||||
|
|
@ -237,6 +269,7 @@ export function Navigation({
|
||||||
previousConversationCount,
|
previousConversationCount,
|
||||||
conversations,
|
conversations,
|
||||||
setCurrentConversationId,
|
setCurrentConversationId,
|
||||||
|
isConversationsLoading,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue