From 7b072dfa70e8639b1a62065868fc135805cad650 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Thu, 26 Mar 2026 23:25:19 +0530 Subject: [PATCH] refactor: streamline message handling in Conversations component - Reorganized imports for better clarity and consistency. - Removed unnecessary parameter from `handleSendMessageWeb` function to simplify its signature. - Updated error handling in `sendMessage` thunk to enhance readability by consolidating the dispatch call for error responses. --- src/pages/Conversations.tsx | 11 +++++------ src/store/threadSlice.ts | 7 ++----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/pages/Conversations.tsx b/src/pages/Conversations.tsx index baeea6411..810de583c 100644 --- a/src/pages/Conversations.tsx +++ b/src/pages/Conversations.tsx @@ -21,15 +21,14 @@ import { import { chatCancel, chatSend, - subscribeChatEvents, - useRustChat, type ChatToolCallEvent, type ChatToolResultEvent, + subscribeChatEvents, + useRustChat, } from '../services/chatService'; +import { store } from '../store'; import { useAppDispatch, useAppSelector } from '../store/hooks'; import type { NotionPageSummary, NotionSummary, NotionUserProfile } from '../store/notionSlice'; -import { store } from '../store'; -import { BACKEND_URL } from '../utils/config'; import { addInferenceResponse, addMessageLocal, @@ -46,6 +45,7 @@ import { setSelectedThread, } from '../store/threadSlice'; import type { ThreadMessage } from '../types/thread'; +import { BACKEND_URL } from '../utils/config'; const MIN_PANEL_WIDTH = 200; const MAX_PANEL_WIDTH = 480; @@ -406,7 +406,6 @@ const Conversations = () => { const handleSendMessageWeb = async ( sendingThreadId: string, trimmed: string, - userMessage: ThreadMessage, historySnapshot: ThreadMessage[] ) => { // Safety-net timeout: force-clear loading states if everything hangs @@ -729,7 +728,7 @@ const Conversations = () => { } } else { // ── Web fallback (existing orchestration logic) ─────────────────────── - await handleSendMessageWeb(sendingThreadId, trimmed, userMessage, historySnapshot); + await handleSendMessageWeb(sendingThreadId, trimmed, historySnapshot); } }; diff --git a/src/store/threadSlice.ts b/src/store/threadSlice.ts index 14aa0767c..43bc82cee 100644 --- a/src/store/threadSlice.ts +++ b/src/store/threadSlice.ts @@ -83,7 +83,7 @@ export const sendMessage = createAsyncThunk( 'thread/sendMessage', async ( { threadId, message }: { threadId: string; message: string }, - { dispatch, getState, rejectWithValue } + { dispatch, rejectWithValue } ) => { // 1. Add user message locally immediately (optimistic update) const userMessage: ThreadMessage = { @@ -116,10 +116,7 @@ export const sendMessage = createAsyncThunk( } catch (error) { // Add an error message as an agent response so the conversation flow continues dispatch( - addInferenceResponse({ - content: 'Something went wrong — please try again.', - threadId, - }) + addInferenceResponse({ content: 'Something went wrong — please try again.', threadId }) ); const msg =