@@ -54,6 +54,7 @@ import { GuestMessageName, guestBubbleClassName } from "./guestMessageStyle";
5454import { MessageCopyButton } from "./MessageCopyButton" ;
5555import { promptLinkFor } from "../promptLinks/copyPromptLink" ;
5656import { PierreEntryIcon } from "./PierreEntryIcon" ;
57+ import { formatBytes } from "../../lib/formatBytes" ;
5758import { shouldCollapseUserMessage } from "./MessagesTimeline.logic" ;
5859import { Tooltip , TooltipPopup , TooltipTrigger } from "../ui/tooltip" ;
5960import {
@@ -88,6 +89,59 @@ const MEDIA_EDGE_CLASS_NAME =
8889const BUBBLE_CHIP_CLASS_NAME =
8990 "[&_[data-slot=context-chip]]:[--context-chip-ink:var(--context-chip-message,var(--context-chip-accent))]" ;
9091
92+ function UserFileCard ( { file } : { readonly file : ChatFileAttachment } ) {
93+ const ctx = use ( TimelineRowCtx ) ;
94+ const extension = / \. ( [ a - z 0 - 9 ] { 1 , 8 } ) $ / i. exec ( file . name ) ?. [ 1 ] ?. toUpperCase ( ) ?? "File" ;
95+ const identity = (
96+ < >
97+ < span className = "flex size-9 shrink-0 items-center justify-center rounded-lg bg-background/60" >
98+ < PierreEntryIcon pathValue = { file . name } kind = "file" theme = { ctx . resolvedTheme } />
99+ </ span >
100+ < span className = "min-w-0 flex-1" >
101+ < span className = "block truncate text-sm font-medium group-hover/file:underline" >
102+ { file . name }
103+ </ span >
104+ < span className = "block text-xs text-muted-foreground tabular-nums" >
105+ { extension } · { formatBytes ( file . sizeBytes ) }
106+ </ span >
107+ </ span >
108+ </ >
109+ ) ;
110+ return (
111+ < div className = "flex w-64 max-w-full items-center gap-1 rounded-2xl bg-message py-2 ps-2 pe-1 text-message-foreground" >
112+ { file . downloadable === false ? (
113+ < div className = "flex min-w-0 flex-1 items-center gap-3" > { identity } </ div >
114+ ) : (
115+ < >
116+ < button
117+ type = "button"
118+ aria-label = { `Preview ${ file . name } ` }
119+ onClick = { ( ) => ctx . onFileOpen ( file ) }
120+ className = "group/file focus-visible:ring-ring/70 flex min-w-0 flex-1 cursor-pointer items-center gap-3 rounded-xl text-left focus-visible:ring-2 focus-visible:ring-inset focus-visible:outline-none"
121+ >
122+ { identity }
123+ </ button >
124+ < Tooltip >
125+ < TooltipTrigger
126+ render = {
127+ < Button
128+ size = "icon-xs"
129+ variant = "ghost-muted"
130+ aria-label = { `Download ${ file . name } ` }
131+ onClick = { ( ) => ctx . onFileDownload ( file ) }
132+ />
133+ }
134+ >
135+ < DownloadIcon />
136+ </ TooltipTrigger >
137+ < TooltipPopup side = "top" > Download { file . name } </ TooltipPopup >
138+ </ Tooltip >
139+ </ >
140+ ) }
141+ </ div >
142+ ) ;
143+ }
144+
91145function UserVideoAttachment ( {
92146 file,
93147 standalone = false ,
@@ -394,6 +448,15 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
394448 userVideos . length === 0 &&
395449 regularImages . length > 1 &&
396450 regularImages . every ( ( image ) => image . source ?. kind !== "snap-shot" ) ;
451+ // Files sent without words show as cards, not as a bubble around a name chip.
452+ const fileCardsOnly =
453+ ! folded &&
454+ userMessage . attribution !== "guest" &&
455+ otherUserFiles . length > 0 &&
456+ regularImages . length + userVideos . length + userAudio . length + unknownAttachments . length === 0 &&
457+ replaceComposerContextReferences ( resolvedContext . text , ( reference ) =>
458+ reference . kind === "file" ? "" : reference . label ,
459+ ) . trim ( ) === "" ;
397460 const annotationRecordIds = resolvedContext . records
398461 . filter ( ( record ) => record . kind === "preview-annotation" )
399462 . map ( ( record ) => record . contextId ) ;
@@ -695,8 +758,8 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
695758 BUBBLE_CHIP_CLASS_NAME ,
696759 userMessage . attribution === "guest"
697760 ? guestBubbleClassName ( false )
698- : ! mediaOnly && "bg-message" ,
699- ! folded && ! mediaOnly && "p-3" ,
761+ : ! mediaOnly && ! fileCardsOnly && "bg-message" ,
762+ ! folded && ! mediaOnly && ! fileCardsOnly && "p-3" ,
700763 folded && expanded && "w-full" ,
701764 ) }
702765 >
@@ -749,7 +812,14 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
749812 ) ) }
750813 </ div >
751814 ) : null }
752- { unchippedFiles . length > 0 || unknownAttachments . length > 0 ? (
815+ { fileCardsOnly ? (
816+ < div className = "flex flex-col items-end gap-1" >
817+ { otherUserFiles . map ( ( file ) => (
818+ < UserFileCard key = { file . id } file = { file } />
819+ ) ) }
820+ </ div >
821+ ) : null }
822+ { ! fileCardsOnly && ( unchippedFiles . length > 0 || unknownAttachments . length > 0 ) ? (
753823 < div className = "mb-2 flex flex-col gap-1" >
754824 { unchippedFiles . map ( ( file ) => {
755825 const fileIdentity = (
@@ -814,15 +884,17 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
814884 ) ) }
815885 </ div >
816886 ) : null }
817- < div onCopyCapture = { onBodyCopyCapture } >
818- < CollapsibleUserMessageBody
819- text = { resolvedContext . text }
820- renderContextReference = { renderContextReference }
821- skills = { ctx . skills }
822- markdownCwd = { ctx . markdownCwd }
823- collapsible = { ! folded }
824- />
825- </ div >
887+ { fileCardsOnly ? null : (
888+ < div onCopyCapture = { onBodyCopyCapture } >
889+ < CollapsibleUserMessageBody
890+ text = { resolvedContext . text }
891+ renderContextReference = { renderContextReference }
892+ skills = { ctx . skills }
893+ markdownCwd = { ctx . markdownCwd }
894+ collapsible = { ! folded }
895+ />
896+ </ div >
897+ ) }
826898 </ div >
827899 ) : null }
828900 </ div >
0 commit comments