feat(messaging-ui): reaction picker + attachments in the Thread
- useMessages exposes upload(); Thread gains a hover reaction picker (react to a message) and an attach button (upload → stage → send), plus inline image / file rendering of message attachments — all capability-degrading (hidden when the adapter lacks react/upload) - themeable styles for the picker, attach button, staged chip, and attachments - 57 tests still green Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useAdapter } from '../provider';
|
||||
import { isOwnMessage } from '../types';
|
||||
import type { Message, SendOpts } from '../types';
|
||||
import type { Attachment, Message, SendOpts } from '../types';
|
||||
|
||||
const TYPING_TTL_MS = 3500;
|
||||
|
||||
@@ -15,6 +15,7 @@ export interface MessagesState {
|
||||
error: string | null;
|
||||
send: (content: string, opts?: SendOpts) => Promise<void>;
|
||||
react: (messageId: string, emoji: string) => Promise<void>;
|
||||
upload: (file: File) => Promise<Attachment>;
|
||||
typingUserIds: string[];
|
||||
seenIds: Set<string>;
|
||||
sendTyping: () => void;
|
||||
@@ -147,6 +148,14 @@ export function useMessages(threadId: string | null): MessagesState {
|
||||
[adapter, threadId],
|
||||
);
|
||||
|
||||
const upload = useCallback(
|
||||
async (file: File): Promise<Attachment> => {
|
||||
if (!adapter.upload) throw new Error('uploads are not supported by this adapter');
|
||||
return adapter.upload(file);
|
||||
},
|
||||
[adapter],
|
||||
);
|
||||
|
||||
const sendTyping = useCallback(() => {
|
||||
if (threadId) adapter.sendTyping(threadId);
|
||||
}, [adapter, threadId]);
|
||||
@@ -196,6 +205,7 @@ export function useMessages(threadId: string | null): MessagesState {
|
||||
error,
|
||||
send,
|
||||
react,
|
||||
upload,
|
||||
typingUserIds,
|
||||
seenIds: seenMine,
|
||||
sendTyping,
|
||||
|
||||
Reference in New Issue
Block a user