properly show new conversations in side nav
This commit is contained in:
parent
5024d7a93a
commit
6934990ec1
3 changed files with 30 additions and 0 deletions
|
|
@ -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) =>
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ const eslintConfig = [
|
|||
rules: {
|
||||
"@typescript-eslint/no-unused-vars": "warn",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"react-hooks/exhaustive-deps": "off",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}, []);
|
||||
|
||||
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,
|
||||
]
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue