feat(app): show loading and error states for assistant images
Render an activity indicator while image dimensions resolve and an "Image unavailable" fallback if loading fails, replacing the previous behavior where the surface stayed blank. Reserves a fixed minimum height in both states so message layout doesn't shift.
This commit is contained in:
@@ -8,6 +8,11 @@ export interface AssistantImageMetadata {
|
||||
aspectRatio: number;
|
||||
}
|
||||
|
||||
export type AssistantImageLoadState =
|
||||
| { status: "loading" }
|
||||
| { status: "ready"; aspectRatio: number }
|
||||
| { status: "error" };
|
||||
|
||||
const assistantImageMetadataCache = new Map<string, AssistantImageMetadata>();
|
||||
const assistantImageParseCache = new Map<string, { sources: string[]; hasNonImageText: boolean }>();
|
||||
const ASSISTANT_IMAGE_METADATA_CACHE_LIMIT = 500;
|
||||
@@ -126,6 +131,15 @@ export function getAssistantImageMetadata(input: {
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getAssistantImageLoadStateFromMetadata(
|
||||
metadata: AssistantImageMetadata | null,
|
||||
): AssistantImageLoadState {
|
||||
if (!metadata) {
|
||||
return { status: "loading" };
|
||||
}
|
||||
return { status: "ready", aspectRatio: metadata.aspectRatio };
|
||||
}
|
||||
|
||||
export function setAssistantImageMetadata(
|
||||
input: {
|
||||
source: string;
|
||||
|
||||
Reference in New Issue
Block a user