Skip to content

Commit 36f35b1

Browse files
fix(ui): resolve composer attachment glyphs
1 parent 2190821 commit 36f35b1

3 files changed

Lines changed: 33 additions & 40 deletions

File tree

‎ui/src/pages/chat/chat-view.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5869,11 +5869,11 @@ describe("chat attachment picker", () => {
58695869
expect(preview.querySelector(".chat-attachment-file__name")?.textContent).toBe("brief.pdf");
58705870
});
58715871

5872-
it("accepts video file attachments with the generic file preview", async () => {
5872+
it("infers video preview glyphs from filenames when MIME is absent", async () => {
58735873
const onAttachmentsChange = vi.fn();
58745874
const container = renderChatView({ onAttachmentsChange });
58755875
const input = container.querySelector<HTMLInputElement>(".agent-chat__file-input");
5876-
const file = new File(["video"], "clip.mp4", { type: "video/mp4" });
5876+
const file = new File(["video"], "clip.mp4");
58775877

58785878
expect(input).toBeInstanceOf(HTMLInputElement);
58795879
expect(input?.accept).toContain("video/*");
@@ -5883,14 +5883,18 @@ describe("chat attachment picker", () => {
58835883
const attachments = requireFirstAttachmentsChange(onAttachmentsChange);
58845884
expect(attachments).toHaveLength(1);
58855885
expect(attachments[0]?.fileName).toBe("clip.mp4");
5886-
expect(attachments[0]?.mimeType).toBe("video/mp4");
5886+
expect(attachments[0]?.mimeType).toBe("application/octet-stream");
58875887
expect(attachments[0]?.sizeBytes).toBe(file.size);
58885888
});
58895889

58905890
const nextAttachments = requireFirstAttachmentsChange(onAttachmentsChange);
58915891
const preview = renderChatView({ attachments: nextAttachments });
58925892
expect(preview.querySelectorAll(".chat-attachment-thumb--file")).toHaveLength(1);
58935893
expect(preview.querySelector(".chat-attachment-file__name")?.textContent).toBe("clip.mp4");
5894+
expect(preview.querySelector(".chat-attachment-file__icon")?.getAttribute("data-family")).toBe(
5895+
"video",
5896+
);
5897+
expect(preview.querySelector(".chat-attachment-file__type")?.textContent).toBe("MP4");
58945898
});
58955899
});
58965900

‎ui/src/pages/chat/components/chat-attachments.ts‎

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,30 @@ function pastedTextPreview(attachment: ChatAttachment): string {
195195
);
196196
}
197197

198-
function attachmentFileGlyph(attachment: ChatAttachment) {
199-
if (attachment.mimeType.startsWith("video/")) {
200-
return icons.play;
201-
}
202-
if (attachment.mimeType.startsWith("audio/")) {
203-
return icons.music;
204-
}
205-
return icons.fileText;
206-
}
207-
208-
function attachmentFileType(attachment: ChatAttachment): string {
209-
return resolveAttachmentFileIcon(attachment.fileName ?? "attachment", attachment.mimeType)
210-
.extensionLabel;
198+
function renderCompactAttachmentFile(attachment: ChatAttachment) {
199+
const resolved = resolveAttachmentFileIcon(
200+
attachment.fileName ?? "attachment",
201+
attachment.mimeType,
202+
);
203+
const glyph =
204+
resolved.family === "video"
205+
? icons.play
206+
: resolved.family === "audio"
207+
? icons.music
208+
: icons.fileText;
209+
return html`
210+
<openclaw-tooltip .content=${attachment.fileName ?? t("chat.attachments.attachedFile")}>
211+
<div class="chat-attachment-file">
212+
<span class="chat-attachment-file__icon" data-family=${resolved.family}>${glyph}</span>
213+
<span class="chat-attachment-file__body">
214+
<span class="chat-attachment-file__name"
215+
>${attachment.fileName ?? t("chat.attachments.attachedFile")}</span
216+
>
217+
<span class="chat-attachment-file__type">${resolved.extensionLabel}</span>
218+
</span>
219+
</div>
220+
</openclaw-tooltip>
221+
`;
211222
}
212223

213224
function appendPastedTextToDraft(draft: string, text: string): string {
@@ -718,25 +729,7 @@ export function renderAttachmentPreview(props: ChatAttachmentControlsProps) {
718729
</span>
719730
</div>
720731
`
721-
: html`
722-
<openclaw-tooltip
723-
.content=${att.fileName ?? t("chat.attachments.attachedFile")}
724-
>
725-
<div class="chat-attachment-file">
726-
<span class="chat-attachment-file__icon"
727-
>${attachmentFileGlyph(att)}</span
728-
>
729-
<span class="chat-attachment-file__body">
730-
<span class="chat-attachment-file__name"
731-
>${att.fileName ?? t("chat.attachments.attachedFile")}</span
732-
>
733-
<span class="chat-attachment-file__type"
734-
>${attachmentFileType(att)}</span
735-
>
736-
</span>
737-
</div>
738-
</openclaw-tooltip>
739-
`}
732+
: renderCompactAttachmentFile(att)}
740733
<openclaw-tooltip .content=${t("chat.composer.removeAttachment")}>
741734
<button
742735
class="chat-attachment-remove"

‎ui/src/styles/chat/layout.css‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6001,11 +6001,7 @@ button.chat-pr__diff {
60016001
}
60026002

60036003
.chat-attachment-thumb--file:is(:hover, :focus-within) .chat-attachment-file {
6004-
background: color-mix(
6005-
in srgb,
6006-
var(--chat-composer-surface, var(--popover)) 86%,
6007-
var(--text)
6008-
);
6004+
background: color-mix(in srgb, var(--chat-composer-surface, var(--popover)) 86%, var(--text));
60096005
}
60106006

60116007
.chat-attachment-file--pasted-text {

0 commit comments

Comments
 (0)