Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(channels): preview attachments in the collapsed mobile composer (#9384)

teod801368f8a7f
diff --git a/apps/web/src/components/ui/components/CollapsedInput.tsx b/apps/web/src/components/ui/components/CollapsedInput.tsx
index 4884376ee3..ea8e1a8368 100644
--- a/apps/web/src/components/ui/components/CollapsedInput.tsx
+++ b/apps/web/src/components/ui/components/CollapsedInput.tsx
@@ -2,7 +2,7 @@ import { focusInput } from '@core/directive/focusInput';
import { isMobile } from '@core/mobile/isMobile';
import { fireAndForget } from '@core/util/fireAndForget';
import PaperclipIcon from '@icon/system/regular/paperclip.svg';
-import { type Accessor, type JSX, Show } from 'solid-js';
+import { type Accessor, children, type JSX, Show } from 'solid-js';
import { cn } from '../utils/classname';
import { Button } from './Button';
import { ComposerSurface } from './ComposerSurface';
@@ -19,6 +19,11 @@ export type CollapsedInputProps = {
renderDraft?: (draft: Accessor<string>) => JSX.Element;
placeholder?: string;
attachmentCount?: number;
+ /**
+ * Shows the draft's attachments before the draft, in place of the
+ * trailing attachment count.
+ */
+ attachmentPreview?: JSX.Element;
/** Renders the send button with a spinner and disables it. */
pending?: boolean;
/**
@@ -50,6 +55,7 @@ export function CollapsedInput(props: CollapsedInputProps) {
const hasText = () => text().length > 0;
const attachmentCount = () => props.attachmentCount ?? 0;
const hasAttachments = () => attachmentCount() > 0;
+ const attachmentPreview = children(() => props.attachmentPreview);
return (
<Layer depth={3} data-collapsed-input>
@@ -82,12 +88,13 @@ export function CollapsedInput(props: CollapsedInputProps) {
type="button"
class={cn(
'min-w-0 flex-1 overflow-hidden rounded-sm px-1.5 text-left text-base outline-none',
- 'flex h-8 items-center text-ink focus-visible:bg-active not-touch:h-[30px] not-touch:px-[5.625px] not-touch:leading-[24.375px]'
+ 'flex h-8 items-center gap-2 text-ink focus-visible:bg-active not-touch:h-[30px] not-touch:px-[5.625px] not-touch:leading-[24.375px]'
)}
ref={attachFocusInput}
onClick={() => props.onOpen?.()}
data-collapsed-input-preview
>
+ {attachmentPreview()}
<Show
when={hasText()}
fallback={
@@ -103,7 +110,7 @@ export function CollapsedInput(props: CollapsedInputProps) {
</div>
</Show>
</button>
- <Show when={hasAttachments() && !hasText()}>
+ <Show when={hasAttachments() && !hasText() && !attachmentPreview()}>
<Button
tooltip={`${attachmentCount()} attachment${
attachmentCount() === 1 ? '' : 's'
diff --git a/apps/web/src/features/channel/Input/ChannelInput.tsx b/apps/web/src/features/channel/Input/ChannelInput.tsx
index 35564a75a3..bef7c14a94 100644
--- a/apps/web/src/features/channel/Input/ChannelInput.tsx
+++ b/apps/web/src/features/channel/Input/ChannelInput.tsx
@@ -66,6 +66,7 @@ import { useAgentMentionUsers } from '../use-agent-mention-users';
import { useMessageBotMentionUsers } from '../use-channel-bot-mention-users';
import { useMessageParticipants } from '../use-message-participants';
import { CHANNEL_FILE_PICKER_ACCEPT } from './accepted-file-types';
+import { CollapsedAttachmentPreview } from './CollapsedAttachmentPreview';
import {
ComposerAddDrawer,
ComposerAddMenu,
@@ -860,6 +861,11 @@ export function ChannelInput(props: ChannelInputProps) {
// mount, but the placeholder can update (e.g. channel name loads).
placeholder={props.input.placeholder}
attachmentCount={inputState.view().attachments?.length ?? 0}
+ attachmentPreview={
+ <CollapsedAttachmentPreview
+ attachments={inputState.view().attachments}
+ />
+ }
pending={inputState.view().hasPendingAttachments}
disabled={!hasSendableInputContent(inputState.view())}
getFocusTarget={() => lexicalEditor().getRootElement()}
diff --git a/apps/web/src/features/channel/Input/CollapsedAttachmentPreview.tsx b/apps/web/src/features/channel/Input/CollapsedAttachmentPreview.tsx
new file mode 100644
index 0000000000..370dabce54
--- /dev/null
+++ b/apps/web/src/features/channel/Input/CollapsedAttachmentPreview.tsx
@@ -0,0 +1,91 @@
+import { MediaImage } from '@channel/Media/MediaImage';
+import { MediaVideo } from '@channel/Media/MediaVideo';
+import { EntityIcon } from '@core/component/EntityIcon';
+import {
+ staticFileIdEndpoint,
+ staticFileSizedEndpoint,
+} from '@core/constant/servers';
+import SpinnerIcon from '@icon/system/regular/spinner-gap.svg';
+import { Match, Show, Switch } from 'solid-js';
+import type { InputAttachmentData } from './types';
+
+const TILE_SIZE = 28;
+
+function PendingThumbnail() {
+ return (
+ <div class="flex size-full items-center justify-center">
+ <SpinnerIcon class="size-3 animate-spin" />
+ </div>
+ );
+}
+
+function AttachmentThumbnail(props: { attachment: InputAttachmentData }) {
+ const isPending = () => !!props.attachment.pending;
+
+ return (
+ <Switch fallback={<PendingThumbnail />}>
+ <Match
+ when={
+ props.attachment.kind === 'image' &&
+ (!isPending() || props.attachment.previewSrc)
+ }
+ >
+ {/* The size the expanded attachment strip loads, so collapsing
+ and expanding share one cached image. */}
+ <MediaImage.Image
+ src={staticFileSizedEndpoint(props.attachment.id, 'medium')}
+ previewSrc={props.attachment.previewSrc}
+ class="size-full object-cover"
+ width={TILE_SIZE}
+ height={TILE_SIZE}
+ fallback={<PendingThumbnail />}
+ />
+ </Match>
+ <Match when={props.attachment.kind === 'video' && !isPending()}>
+ <MediaVideo.Preview
+ src={staticFileIdEndpoint(props.attachment.id)}
+ class="size-full object-cover"
+ />
+ </Match>
+ <Match when={props.attachment.kind === 'document' && !isPending()}>
+ <div class="flex size-full items-center justify-center">
+ <EntityIcon
+ targetType={props.attachment.iconType ?? 'unknown'}
+ size="xs"
+ />
+ </div>
+ </Match>
+ </Switch>
+ );
+}
+
+/**
+ * A draft's attachments in a collapsed composer: a thumbnail of the first
+ * one, with the number of attachments over it when there are several.
+ */
+export function CollapsedAttachmentPreview(props: {
+ attachments?: InputAttachmentData[];
+}) {
+ const count = () => props.attachments?.length ?? 0;
+
+ return (
+ <Show when={props.attachments?.[0]}>
+ {(first) => (
+ <div
+ role="img"
+ aria-label={`${count()} attachment${count() === 1 ? '' : 's'}`}
+ // The tap belongs to the collapsed input, which opens the composer.
+ class="ph-no-capture pointer-events-none relative size-7 shrink-0 overflow-hidden rounded-md border border-edge bg-surface"
+ data-collapsed-input-attachment-preview
+ >
+ <AttachmentThumbnail attachment={first()} />
+ <Show when={count() > 1}>
+ <span class="absolute inset-0 flex items-center justify-center bg-surface/60 text-xs font-medium text-ink">
+ {count()}
+ </span>
+ </Show>
+ </div>
+ )}
+ </Show>
+ );
+}
diff --git a/apps/web/src/features/channel/Input/tests/input-slots.test.tsx b/apps/web/src/features/channel/Input/tests/input-slots.test.tsx
index 0ed301ac9d..0c2904a7af 100644
--- a/apps/web/src/features/channel/Input/tests/input-slots.test.tsx
+++ b/apps/web/src/features/channel/Input/tests/input-slots.test.tsx
@@ -496,6 +496,34 @@ describe('Input slots', () => {
).toBeNull();
});
+ it('previews a collapsed draft’s attachments before its text and opens the composer from them', async () => {
+ const user = userEvent.setup();
+ device.touch = true;
+ vi.mocked(isMobile).mockReturnValue(true);
+ const { container } = render(() => (
+ <ChannelInput
+ input={{ ...baseInput, value: 'see attached' }}
+ attachmentTracker={createInputAttachmentTracker({
+ initialAttachments: [
+ { id: 'image-1', name: 'photo.png', kind: 'image' },
+ { id: 'doc-1', name: 'notes.pdf', kind: 'document' },
+ { id: 'image-2', name: 'photo-2.png', kind: 'image' },
+ ],
+ })}
+ collapsible
+ />
+ ));
+
+ const preview = screen.getByRole('img', { name: '3 attachments' });
+ expect(preview.textContent).toBe('3');
+ const collapsedInput = preview.closest('button');
+ expect(collapsedInput?.textContent).toContain('see attached');
+ expect(screen.queryByRole('button', { name: '3 attachments' })).toBeNull();
+
+ await user.click(collapsedInput as HTMLElement);
+ expect(container.querySelector('[data-composer-collapsed]')).toBeNull();
+ });
+
it('offers Cursor and Codex within their rollouts before account setup', () => {
editorMocks.cursorEnabled = true;
editorMocks.codexEnabled = true;
diff --git a/docs/agent-guide/channels.md b/docs/agent-guide/channels.md
index bbc278314c..d6f7cf3cc9 100644
--- a/docs/agent-guide/channels.md
+++ b/docs/agent-guide/channels.md
@@ -392,6 +392,12 @@ after the first three (five participants shows **+2**).
Drag the handle, tap the backdrop, or press Escape to dismiss without starting a
call. Only confirming notifies participants; joining a live call skips the sheet.
Check both DMs and channels, including long names, in light and dark themes.
+On phones, a collapsed composer with attachments shows a thumbnail of the
+first one between `+` and the draft, with the number of attachments over it
+when there are two or more; a document shows its file icon. It shows with or
+without draft text, and tapping it opens the composer with the attachments
+below the editor. Check one image, several mixed attachments, and a document
+alone, with and without text, in light and dark themes.
Input action and formatting buttons show the app tooltip without a second
native browser tooltip.
On desktop, select draft text to open the floating formatting toolbar. Its