feat(chat-hook): set ready before reconnecting

This commit is contained in:
ItzCrazyKns
2025-12-23 17:29:14 +05:30
parent c3b74a3fd0
commit 2c65bd916b

View File

@@ -269,6 +269,7 @@ export const chatContext = createContext<ChatContext>({
export const ChatProvider = ({ children }: { children: React.ReactNode }) => {
const params: { chatId: string } = useParams();
const searchParams = useSearchParams();
const initialMessage = searchParams.get('q');
@@ -402,6 +403,9 @@ export const ChatProvider = ({ children }: { children: React.ReactNode }) => {
}, [messages]);
const checkReconnect = async () => {
setIsReady(true);
console.debug(new Date(), 'app:ready');
if (messages.length > 0) {
const lastMsg = messages[messages.length - 1];
@@ -503,13 +507,6 @@ export const ChatProvider = ({ children }: { children: React.ReactNode }) => {
console.debug(new Date(), 'app:ready');
} else if (isMessagesLoaded && isConfigReady && !newChatCreated) {
checkReconnect()
.then(() => {
setIsReady(true);
console.debug(new Date(), 'app:ready');
})
.catch((err) => {
console.error('Error during reconnect:', err);
});
} else {
setIsReady(false);
}