|
1 | 1 | // Control UI chat module implements chat avatar behavior. |
2 | 2 | import { html, nothing } from "lit"; |
3 | | -import { keyed } from "lit/directives/keyed.js"; |
| 3 | +import { live } from "lit/directives/live.js"; |
4 | 4 | import { until } from "lit/directives/until.js"; |
5 | 5 | import type { GatewayHelloOk } from "../../api/gateway.ts"; |
6 | 6 | import { normalizeBasePath } from "../../app-route-paths.ts"; |
@@ -65,32 +65,31 @@ export function renderChatAvatar( |
65 | 65 | // The derived route may 404 (no upload, no Gravatar); swap to initials |
66 | 66 | // instead of a broken image. Lit reuses DOM parts, so a load must clear a |
67 | 67 | // prior sender's error state. |
68 | | - return html`${keyed( |
69 | | - imageUrl, |
70 | | - html`<span class=${`chat-avatar-slot${typeof imageUrl === "string" ? "" : " is-fallback"}`}> |
71 | | - <img |
72 | | - class="chat-avatar user" |
73 | | - src=${typeof imageUrl === "string" |
74 | | - ? imageUrl |
75 | | - : until( |
76 | | - imageUrl.then((url) => url ?? nothing), |
77 | | - nothing, |
78 | | - )} |
79 | | - alt="${label}" |
80 | | - @error=${(event: Event) => { |
81 | | - const image = event.currentTarget as HTMLImageElement; |
82 | | - settleAvatarImageUrl(image.getAttribute("src")); |
83 | | - image.closest(".chat-avatar-slot")?.classList.add("is-fallback"); |
84 | | - }} |
85 | | - @load=${(event: Event) => { |
86 | | - const image = event.currentTarget as HTMLImageElement; |
87 | | - settleAvatarImageUrl(image.getAttribute("src")); |
88 | | - image.closest(".chat-avatar-slot")?.classList.remove("is-fallback"); |
89 | | - }} |
90 | | - /> |
91 | | - ${initialsAvatar} |
92 | | - </span>`, |
93 | | - )}`; |
| 68 | + return html`<span |
| 69 | + class=${live(`chat-avatar-slot${typeof imageUrl === "string" ? "" : " is-fallback"}`)} |
| 70 | + > |
| 71 | + <img |
| 72 | + class="chat-avatar user" |
| 73 | + src=${typeof imageUrl === "string" |
| 74 | + ? imageUrl |
| 75 | + : until( |
| 76 | + imageUrl.then((url) => url ?? nothing), |
| 77 | + nothing, |
| 78 | + )} |
| 79 | + alt="${label}" |
| 80 | + @error=${(event: Event) => { |
| 81 | + const image = event.currentTarget as HTMLImageElement; |
| 82 | + settleAvatarImageUrl(image.getAttribute("src")); |
| 83 | + image.closest(".chat-avatar-slot")?.classList.add("is-fallback"); |
| 84 | + }} |
| 85 | + @load=${(event: Event) => { |
| 86 | + const image = event.currentTarget as HTMLImageElement; |
| 87 | + settleAvatarImageUrl(image.getAttribute("src")); |
| 88 | + image.closest(".chat-avatar-slot")?.classList.remove("is-fallback"); |
| 89 | + }} |
| 90 | + /> |
| 91 | + ${initialsAvatar} |
| 92 | + </span>`; |
94 | 93 | } |
95 | 94 | const assistantName = assistant?.name?.trim() || "Assistant"; |
96 | 95 | const assistantAvatar = assistant?.avatar?.trim() || ""; |
|
0 commit comments