Skip to content

Commit 452f18a

Browse files
Julius Marmingeclaude
andcommitted
fix(web): sent videos play inline through the shared player
The play tile opened a dialog around the same player; the tile now is the player, with retry and the media menu, matching markdown and workspace videos. The dialog path for sent videos had no caller left and is removed. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 670f1b3 commit 452f18a

4 files changed

Lines changed: 88 additions & 51 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ import {
134134
type ChatMessage,
135135
isBrowserPreviewAttachment,
136136
isImageAttachment,
137-
videoMimeType,
138137
type SessionPhase,
139138
type Thread,
140139
type TurnDiffSummary,
@@ -299,11 +298,7 @@ import type { AssistantCitationRequest } from "./chat/AssistantCitationSource";
299298
import { resolveTimelineIsAtEnd } from "./chat/MessagesTimeline.logic";
300299
import { ChatHeader } from "./chat/ChatHeader";
301300
import { PanelLayoutControls, RightPanelMaximizeControl } from "./chat/PanelLayoutControls";
302-
import {
303-
buildAttachmentVideoPreview,
304-
expandedImageKey,
305-
type ExpandedImagePreview,
306-
} from "./chat/ExpandedImagePreview";
301+
import { expandedImageKey, type ExpandedImagePreview } from "./chat/ExpandedImagePreview";
307302
import { NoActiveThreadState } from "./NoActiveThreadState";
308303
import { WorkspacePageHeader } from "./WorkspacePageHeader";
309304
import {
@@ -2634,13 +2629,9 @@ function ChatViewContent(props: ChatViewProps) {
26342629
useRightPanelStore.getState().openAttachment(activeThreadRef, attachment);
26352630
return;
26362631
}
2637-
if (videoMimeType(attachment) !== null) {
2638-
setExpandedImage(buildAttachmentVideoPreview(environmentId, attachment));
2639-
return;
2640-
}
26412632
void downloadFileAttachment(attachment);
26422633
},
2643-
[activeThreadRef, downloadFileAttachment, environmentId],
2634+
[activeThreadRef, downloadFileAttachment],
26442635
);
26452636
const serverAttachmentIds = useMemo(() => {
26462637
const attachmentIds = new Set<string>();

‎apps/web/src/components/chat/ExpandedImagePreview.tsx‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ export async function resolveMarkdownMediaPreview(input: {
101101
};
102102
}
103103

104-
export function buildAttachmentVideoPreview(
104+
export function buildAttachmentVideoAsset(
105105
environmentId: EnvironmentId,
106106
attachment: ChatFileAttachment,
107-
): ExpandedImagePreview {
108-
const asset = {
107+
): NonNullable<MediaActionSource["asset"]> {
108+
return {
109109
environmentId,
110110
resource: {
111111
_tag: "attachment" as const,
@@ -114,17 +114,6 @@ export function buildAttachmentVideoPreview(
114114
mimeType: videoMimeType(attachment) ?? attachment.mimeType,
115115
},
116116
};
117-
return {
118-
images: [
119-
{
120-
src: null,
121-
name: attachment.name,
122-
type: "video",
123-
actionsSource: { kind: "video", name: attachment.name, src: null, asset },
124-
},
125-
],
126-
index: 0,
127-
};
128117
}
129118

130119
export function expandedImageKey(preview: ExpandedImagePreview): string {

‎apps/web/src/components/chat/MessagesTimeline.test.tsx‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ describe("MessagesTimeline", () => {
464464
expect(markup).not.toContain('alt="report.pdf"');
465465
});
466466

467-
it("renders video attachments as play buttons", () => {
467+
it("renders video attachments with the shared video player", () => {
468468
const entry = {
469469
...buildUserTimelineEntry("Watch the demo."),
470470
message: {
@@ -476,6 +476,7 @@ describe("MessagesTimeline", () => {
476476
name: "demo.mp4",
477477
mimeType: "video/mp4",
478478
sizeBytes: 42,
479+
previewUrl: "https://environment.test/api/assets/demo.mp4",
479480
},
480481
],
481482
},
@@ -485,10 +486,36 @@ describe("MessagesTimeline", () => {
485486
<MessagesTimeline {...buildProps()} timelineEntries={[entry]} />,
486487
);
487488

488-
expect(markup).toContain('aria-label="Play demo.mp4"');
489-
expect(markup).toContain("min-h-[72px]");
490-
expect(markup).toContain(">demo.mp4</span>");
491-
expect(markup).not.toContain('aria-label="Download demo.mp4"');
489+
expect(markup).toContain("<video");
490+
expect(markup).toContain('aria-label="demo.mp4"');
491+
expect(markup).toContain('controls=""');
492+
expect(markup).not.toContain("Expand demo.mp4");
493+
});
494+
495+
it("shows the filename while an optimistic video is unavailable", () => {
496+
const entry = {
497+
...buildUserTimelineEntry("Uploading the demo."),
498+
message: {
499+
...buildUserTimelineEntry("Uploading the demo.").message,
500+
attachments: [
501+
{
502+
type: "file" as const,
503+
id: "optimistic-demo-mp4",
504+
name: "pending-demo.mp4",
505+
mimeType: "video/mp4",
506+
sizeBytes: 42,
507+
downloadable: false,
508+
},
509+
],
510+
},
511+
};
512+
513+
const markup = renderToStaticMarkup(
514+
<MessagesTimeline {...buildProps()} timelineEntries={[entry]} />,
515+
);
516+
517+
expect(markup).not.toContain("<video");
518+
expect(markup).toContain(">pending-demo.mp4</div>");
492519
});
493520
it("renders an ordinary file download button without creating its URL in advance", () => {
494521
const entry = {

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
type AssistantCitation,
3-
type ChatFileAttachment,
43
type EnvironmentId,
54
type MessageId,
65
type ScopedThreadRef,
@@ -50,6 +49,7 @@ import {
5049
workLogEntryIsToolLike,
5150
} from "../../session-logic";
5251
import {
52+
type ChatFileAttachment,
5353
type ChatImageAttachment,
5454
isBrowserPreviewAttachment,
5555
isFileAttachment,
@@ -79,7 +79,6 @@ import {
7979
MessageCircleIcon,
8080
MousePointerClickIcon,
8181
PaintbrushIcon,
82-
PlayIcon,
8382
SearchIcon,
8483
SquarePenIcon,
8584
TerminalIcon,
@@ -89,8 +88,14 @@ import {
8988
ZapIcon,
9089
} from "lucide-react";
9190
import { Button } from "../ui/button";
91+
import { useAssetUrlRefresh, useAssetUrlState } from "../../assets/assetUrls";
92+
import { MediaVideoPlayer } from "../media/MediaVideoPlayer";
9293
import { getVirtualizedScrollFadeClassName } from "../ui/scroll-area";
93-
import { buildExpandedImagePreview, ExpandedImagePreview } from "./ExpandedImagePreview";
94+
import {
95+
buildAttachmentVideoAsset,
96+
buildExpandedImagePreview,
97+
ExpandedImagePreview,
98+
} from "./ExpandedImagePreview";
9499
import { ProposedPlanCard } from "./ProposedPlanCard";
95100
import { ChangedFilesCard } from "./ChangedFilesTree";
96101
import { shouldAutoExpandChangedFiles } from "./changedFilesPresentation";
@@ -1117,6 +1122,45 @@ const TimelineRowContent = memo(function TimelineRowContent({ row }: { row: Time
11171122
);
11181123
});
11191124

1125+
function UserVideoAttachment({ file }: { readonly file: ChatFileAttachment }) {
1126+
const ctx = use(TimelineRowCtx);
1127+
const asset = useMemo(
1128+
() =>
1129+
file.downloadable === false
1130+
? null
1131+
: buildAttachmentVideoAsset(ctx.activeThreadEnvironmentId, file),
1132+
[ctx.activeThreadEnvironmentId, file.downloadable, file.id, file.mimeType, file.name],
1133+
);
1134+
const resource = asset?.resource ?? null;
1135+
const assetUrl = useAssetUrlState(ctx.activeThreadEnvironmentId, resource);
1136+
const refreshAssetUrl = useAssetUrlRefresh(ctx.activeThreadEnvironmentId, resource);
1137+
const src = assetUrl._tag === "Success" ? assetUrl.url : (file.previewUrl ?? null);
1138+
1139+
if (asset === null && src === null) {
1140+
return (
1141+
<div className="flex aspect-[4/3] w-full items-center justify-center rounded-lg border border-border/80 bg-black px-2 py-3 text-center text-[11px] text-white/70">
1142+
{file.name}
1143+
</div>
1144+
);
1145+
}
1146+
1147+
return (
1148+
<MediaVideoPlayer
1149+
src={src}
1150+
sourceFailed={
1151+
file.previewUrl === undefined && resource !== null && assetUrl._tag === "Failure"
1152+
}
1153+
label={file.name}
1154+
preload="visible"
1155+
className="block aspect-[4/3] w-full"
1156+
videoClassName="aspect-auto size-full rounded-lg border border-border/80"
1157+
stateClassName="aspect-auto min-h-full rounded-lg border border-border/80 bg-black text-white"
1158+
onRetry={asset ? refreshAssetUrl : undefined}
1159+
actionsSource={asset ? { kind: "video", name: file.name, src, asset } : undefined}
1160+
/>
1161+
);
1162+
}
1163+
11201164
function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
11211165
const ctx = use(TimelineRowCtx);
11221166
// The attachment union has an open member, so guards (not literal type
@@ -1155,12 +1199,12 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
11551199
{regularImages.map((image) => (
11561200
<div
11571201
key={image.id}
1158-
className="overflow-hidden rounded-lg border border-border/80 bg-background/70"
1202+
className="aspect-[4/3] overflow-hidden rounded-lg border border-border/80 bg-background/70"
11591203
>
11601204
{image.previewUrl ? (
11611205
<button
11621206
type="button"
1163-
className="h-full w-full cursor-zoom-in"
1207+
className="block h-full w-full cursor-zoom-in"
11641208
aria-label={`Preview ${image.name}`}
11651209
onClick={() => {
11661210
const preview = buildExpandedImagePreview(regularImages, image.id);
@@ -1171,7 +1215,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
11711215
<img
11721216
src={image.previewUrl}
11731217
alt={image.name}
1174-
className="block h-auto max-h-[220px] w-full object-cover"
1218+
className="block size-full object-cover"
11751219
/>
11761220
</button>
11771221
) : (
@@ -1182,21 +1226,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
11821226
</div>
11831227
))}
11841228
{userVideos.map((file) => (
1185-
<div
1186-
key={file.id}
1187-
className="overflow-hidden rounded-lg border border-border/80 bg-black"
1188-
>
1189-
<button
1190-
type="button"
1191-
disabled={file.downloadable === false}
1192-
className="flex min-h-[72px] w-full cursor-zoom-in flex-col items-center justify-center gap-1 px-2 py-2 text-white disabled:cursor-default disabled:opacity-50"
1193-
aria-label={`Play ${file.name}`}
1194-
onClick={() => ctx.onFileOpen(file)}
1195-
>
1196-
<PlayIcon className="size-8 fill-current" />
1197-
<span className="max-w-full truncate text-[11px]">{file.name}</span>
1198-
</button>
1199-
</div>
1229+
<UserVideoAttachment key={file.id} file={file} />
12001230
))}
12011231
</div>
12021232
)}

0 commit comments

Comments
 (0)