feat: optimistic message rendering with send status indicators

- User messages appear instantly with 'sending' state (dimmed, clock icon)
- Transitions to 'sent' (checkmark) when server acknowledges
- Shows error state (alert icon, retry visible) if send fails
- Applied to both primary and secondary sessions
This commit is contained in:
Nicolas Varrot
2026-02-13 09:12:09 +00:00
parent 495dd0352f
commit b783ae181b
11 changed files with 96 additions and 44 deletions

View File

@@ -214,12 +214,14 @@ export function useSecondarySession(
const sendMessage = useCallback(async (text: string, attachments?: Array<{ mimeType: string; fileName: string; content: string }>) => {
if (!sessionKeyRef.current) return;
const msgId = 'user-' + Date.now();
const userMsg: ChatMessage = {
id: 'user-' + Date.now(),
id: msgId,
role: 'user',
content: text,
timestamp: Date.now(),
blocks: [{ type: 'text', text }],
sendStatus: 'sending',
};
setMessages(prev => [...prev, userMsg]);
setIsGenerating(true);
@@ -230,7 +232,9 @@ export function useSecondarySession(
deliver: false,
...(attachments && attachments.length > 0 ? { attachments } : {}),
});
setMessages(prev => prev.map(m => m.id === msgId ? { ...m, sendStatus: 'sent' as const } : m));
} catch {
setMessages(prev => prev.map(m => m.id === msgId ? { ...m, sendStatus: 'error' as const } : m));
setIsGenerating(false);
}
}, [getClient]);