diff --git a/frontend/src/conversation/conversationSlice.ts b/frontend/src/conversation/conversationSlice.ts index 081d5871..036962c4 100644 --- a/frontend/src/conversation/conversationSlice.ts +++ b/frontend/src/conversation/conversationSlice.ts @@ -3,7 +3,10 @@ import { createAsyncThunk, createSlice, PayloadAction } from '@reduxjs/toolkit'; import { getConversations } from '../preferences/preferenceApi'; import { setConversations } from '../preferences/preferenceSlice'; import store from '../store'; -import { selectCompletedAttachments } from '../upload/uploadSlice'; +import { + selectCompletedAttachments, + clearAttachments, +} from '../upload/uploadSlice'; import { handleFetchAnswer, handleFetchAnswerSteaming, @@ -41,6 +44,11 @@ export const fetchAnswer = createAsyncThunk< const attachmentIds = selectCompletedAttachments(state) .filter((a) => a.id) .map((a) => a.id) as string[]; + + if (attachmentIds.length > 0) { + dispatch(clearAttachments()); + } + const currentConversationId = state.conversation.conversationId; const conversationIdToSend = isPreview ? null : currentConversationId; const save_conversation = isPreview ? false : true; diff --git a/frontend/src/conversation/sharedConversationSlice.ts b/frontend/src/conversation/sharedConversationSlice.ts index ae295412..df2650a3 100644 --- a/frontend/src/conversation/sharedConversationSlice.ts +++ b/frontend/src/conversation/sharedConversationSlice.ts @@ -7,7 +7,10 @@ import { handleFetchSharedAnswer, handleFetchSharedAnswerStreaming, } from './conversationHandlers'; -import { selectCompletedAttachments } from '../upload/uploadSlice'; +import { + selectCompletedAttachments, + clearAttachments, +} from '../upload/uploadSlice'; const API_STREAMING = import.meta.env.VITE_API_STREAMING === 'true'; interface SharedConversationsType { @@ -34,6 +37,10 @@ export const fetchSharedAnswer = createAsyncThunk( .filter((a) => a.id) .map((a) => a.id) as string[]; + if (attachmentIds.length > 0) { + dispatch(clearAttachments()); + } + if (state.preference && state.sharedConversation.apiKey) { if (API_STREAMING) { await handleFetchSharedAnswerStreaming( diff --git a/frontend/src/upload/uploadSlice.ts b/frontend/src/upload/uploadSlice.ts index fff56dbd..732c69bc 100644 --- a/frontend/src/upload/uploadSlice.ts +++ b/frontend/src/upload/uploadSlice.ts @@ -48,7 +48,9 @@ export const uploadSlice = createSlice({ ); }, clearAttachments: (state) => { - state.attachments = []; + state.attachments = state.attachments.filter( + (att) => att.status === 'uploading' || att.status === 'processing', + ); }, }, });