From ebbd47c9cbdb5726b7e9b0aed00b58a8994ac7c9 Mon Sep 17 00:00:00 2001 From: Siddhant Rai Date: Wed, 6 Nov 2024 21:34:57 +0530 Subject: [PATCH] fix: pending sources even when no sources provided --- frontend/src/conversation/conversationSlice.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/frontend/src/conversation/conversationSlice.ts b/frontend/src/conversation/conversationSlice.ts index 1b7e9d41..3ca05c7b 100644 --- a/frontend/src/conversation/conversationSlice.ts +++ b/frontend/src/conversation/conversationSlice.ts @@ -20,6 +20,7 @@ const API_STREAMING = import.meta.env.VITE_API_STREAMING === 'true'; export const fetchAnswer = createAsyncThunk( 'fetchAnswer', async ({ question }, { dispatch, getState, signal }) => { + let isSourceUpdated = false; const state = getState() as RootState; if (state.preference) { if (API_STREAMING) { @@ -36,9 +37,7 @@ export const fetchAnswer = createAsyncThunk( (event) => { const data = JSON.parse(event.data); - // check if the 'end' event has been received if (data.type === 'end') { - // set status to 'idle' dispatch(conversationSlice.actions.setStatus('idle')); getConversations() .then((fetchedConversations) => { @@ -47,6 +46,14 @@ export const fetchAnswer = createAsyncThunk( .catch((error) => { console.error('Failed to fetch conversations: ', error); }); + if (!isSourceUpdated) { + dispatch( + updateStreamingSource({ + index: state.conversation.queries.length - 1, + query: { sources: [] }, + }), + ); + } } else if (data.type === 'id') { dispatch( updateConversationId({ @@ -54,6 +61,7 @@ export const fetchAnswer = createAsyncThunk( }), ); } else if (data.type === 'source') { + isSourceUpdated = true; dispatch( updateStreamingSource({ index: state.conversation.queries.length - 1,