Skip to content

Commit 4172780

Browse files
committed
perf(ui): prepare attachment icon mode once
1 parent 8249fd6 commit 4172780

2 files changed

Lines changed: 19 additions & 27 deletions

File tree

‎ui/src/pages/chat/components/chat-attachment-file-icon.ts‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,18 @@ export function renderAttachmentFileIcon(options: {
271271
unavailable?: boolean;
272272
}) {
273273
const resolved = resolveAttachmentFileIcon(options.filename, options.mimeType);
274-
const compactLight = resolved.compact
275-
? fileIconAssetPath(`compact/light/${resolved.compact}`)
276-
: fileIconAssetPath("compact/unknown-light");
277-
const compactDark = resolved.compact
278-
? fileIconAssetPath(`compact/dark/${resolved.compact}`)
279-
: fileIconAssetPath("compact/unknown-dark");
274+
const large = options.mode === "large-placeholder";
275+
const size = large ? "44px" : "20px";
276+
const light = large
277+
? fileIconAssetPath("large/shell-light")
278+
: resolved.compact
279+
? fileIconAssetPath(`compact/light/${resolved.compact}`)
280+
: fileIconAssetPath("compact/unknown-light");
281+
const dark = large
282+
? fileIconAssetPath("large/shell-dark")
283+
: resolved.compact
284+
? fileIconAssetPath(`compact/dark/${resolved.compact}`)
285+
: fileIconAssetPath("compact/unknown-dark");
280286
return html`<span
281287
class="chat-attachment-file-icon ${options.unavailable
282288
? "chat-attachment-file-icon--unavailable"
@@ -285,16 +291,14 @@ export function renderAttachmentFileIcon(options: {
285291
data-mode=${options.mode}
286292
aria-hidden="true"
287293
style=${styleMap({
288-
"--chat-file-icon-shell-light": `url("${fileIconAssetPath("large/shell-light")}")`,
289-
"--chat-file-icon-shell-dark": `url("${fileIconAssetPath("large/shell-dark")}")`,
294+
width: size,
295+
height: size,
296+
"--chat-file-icon-light": `url("${light}")`,
297+
"--chat-file-icon-dark": `url("${dark}")`,
290298
"--chat-file-icon-overlay": `url("${fileIconAssetPath(`overlays/${resolved.family}`)}")`,
291299
"--chat-file-icon-accent": resolved.accent,
292-
"--chat-file-icon-compact-light": `url("${compactLight}")`,
293-
"--chat-file-icon-compact-dark": `url("${compactDark}")`,
294300
})}
295301
>
296-
${options.mode === "large-placeholder"
297-
? html`<span class="chat-attachment-file-icon__overlay"></span>`
298-
: null}
302+
${large ? html`<span class="chat-attachment-file-icon__overlay"></span>` : null}
299303
</span>`;
300304
}

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,12 @@
22
position: relative;
33
display: inline-block;
44
flex: none;
5-
width: 44px;
6-
height: 44px;
75
color: var(--file-icon-glyph);
8-
background: var(--chat-file-icon-shell-dark) center / contain no-repeat;
9-
}
10-
11-
.chat-attachment-file-icon[data-mode="preview-with-favicon"] {
12-
width: 20px;
13-
height: 20px;
14-
background-image: var(--chat-file-icon-compact-dark);
6+
background: var(--chat-file-icon-dark) center / contain no-repeat;
157
}
168

179
:root[data-theme-mode="light"] .chat-attachment-file-icon {
18-
background-image: var(--chat-file-icon-shell-light);
19-
}
20-
21-
:root[data-theme-mode="light"] .chat-attachment-file-icon[data-mode="preview-with-favicon"] {
22-
background-image: var(--chat-file-icon-compact-light);
10+
background-image: var(--chat-file-icon-light);
2311
}
2412

2513
.chat-attachment-file-icon__overlay {

0 commit comments

Comments
 (0)