Skip to content

Commit cb05e21

Browse files
feat(frontend): add simple chat mode for user messages and clean up redundant optimistic filtering
1 parent f5d1abe commit cb05e21

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

frontend/src/components/message/MessageThread.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { MessageError } from './MessageError'
77
import type { Message, Part, MessageWithParts } from '@/api/types'
88
import { useSessionStatusForSession } from '@/stores/sessionStatusStore'
99
import { useSessionTodos } from '@/stores/sessionTodosStore'
10+
import { useSettings } from '@/hooks/useSettings'
1011
import type { components } from '@/api/opencode-types'
1112
import type { Todo } from '@/components/message/SessionTodoDisplay'
1213
import type { OpenCodeError } from '@/lib/opencode-errors'
@@ -78,6 +79,7 @@ interface MessageRowProps {
7879
handleStartEditUserMessage: (userMessageId: string, assistantMessageId: string) => void
7980
handleCancelEdit: () => void
8081
model?: string
82+
simpleChatMode: boolean
8183
}
8284

8385
const MessageRow = memo(function MessageRow({
@@ -98,6 +100,7 @@ const MessageRow = memo(function MessageRow({
98100
handleStartEditUserMessage,
99101
handleCancelEdit,
100102
model,
103+
simpleChatMode,
101104
}: MessageRowProps) {
102105
const msg = msgWithParts.info
103106
const parts = msgWithParts.parts
@@ -185,6 +188,12 @@ const MessageRow = memo(function MessageRow({
185188
onClick={() => handleStartEditUserMessage(msg.id, nextAssistantMsg.id)}
186189
isEditable={false}
187190
/>
191+
) : msg.role === 'user' && simpleChatMode ? (
192+
<ClickableUserMessage
193+
content={messageTextContent}
194+
onClick={() => {}}
195+
isEditable={false}
196+
/>
188197
) : parts.length > 0 ? (
189198
parts.map((part: Part, partIndex: number) => (
190199
<div key={`${msg.id}-${part.id}-${partIndex}`}>
@@ -222,6 +231,8 @@ export const MessageThread = memo(function MessageThread({
222231
const [editingUserMessageId, setEditingUserMessageId] = useState<string | null>(null)
223232
const [editingForAssistantId, setEditingForAssistantId] = useState<string | null>(null)
224233
const sessionStatus = useSessionStatusForSession(sessionID)
234+
const { preferences } = useSettings()
235+
const simpleChatMode = preferences?.simpleChatMode ?? false
225236

226237
const pendingAssistantId = useMemo(() => {
227238
if (!messages) return undefined
@@ -316,6 +327,7 @@ export const MessageThread = memo(function MessageThread({
316327
handleStartEditUserMessage={handleStartEditUserMessage}
317328
handleCancelEdit={handleCancelEdit}
318329
model={model}
330+
simpleChatMode={simpleChatMode}
319331
/>
320332
))}
321333
</div>

frontend/src/hooks/useOpenCode.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,23 +331,22 @@ export const useSendPrompt = (opcodeUrl: string | null | undefined, directory?:
331331
},
332332
onSuccess: async (data, variables) => {
333333
const { sessionID } = variables;
334-
const { optimisticUserID, response } = data;
334+
const { response } = data;
335335
const messagesQueryKey = ["opencode", "messages", opcodeUrl, sessionID, directory];
336336

337337
queryClient.setQueryData<MessageWithParts[]>(
338338
messagesQueryKey,
339339
(old) => {
340340
if (!old) return old;
341-
const withoutOptimistic = old.filter((msgWithParts) => msgWithParts.info.id !== optimisticUserID);
342-
343-
const existingIdx = withoutOptimistic.findIndex(m => m.info.id === response.info.id);
341+
342+
const existingIdx = old.findIndex(m => m.info.id === response.info.id);
344343
if (existingIdx >= 0) {
345-
const updated = [...withoutOptimistic];
344+
const updated = [...old];
346345
updated[existingIdx] = { info: response.info, parts: response.parts };
347346
return updated;
348347
}
349-
350-
return [...withoutOptimistic, { info: response.info, parts: response.parts }];
348+
349+
return [...old, { info: response.info, parts: response.parts }];
351350
},
352351
);
353352

0 commit comments

Comments
 (0)