Skip to content

Commit 1dd7d42

Browse files
committed
fix(workspace): only request a page thumbnail for documents that render a page
CSV, Excel, email and text documents have no rendered page image, so the work queue thumbnail 404'd on /pages/1.png and noised up the browser console. Gate the image request by file extension (pdf/png/jpg/tiff); other types show the document-type glyph directly with no request.
1 parent 254073c commit 1dd7d42

2 files changed

Lines changed: 30 additions & 14 deletions

File tree

web/components/workspace/queue-thumbnail.tsx

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,27 @@ const glyphFor = (documentType?: ReinsuranceDocumentType) => {
2727

2828
// Lazily probes the document's first page image. Digital documents (e-mail, CSV,
2929
// plain text) have no rendered page, so the request 404s and the type glyph stays.
30+
// Only these formats render a page image; requesting one for any other type
31+
// (CSV, Excel, e-mail, plain text) just 404s and noises up the console.
32+
const PAGE_IMAGE_EXTENSIONS = [".pdf", ".png", ".jpg", ".jpeg", ".tif", ".tiff"];
33+
34+
const rendersPage = (fileName?: string): boolean => {
35+
const lower = (fileName ?? "").toLowerCase();
36+
return PAGE_IMAGE_EXTENSIONS.some((extension) => lower.endsWith(extension));
37+
};
38+
3039
export function QueueThumbnail({
3140
documentId,
3241
documentType,
42+
fileName,
3343
}: {
3444
documentId: string;
3545
documentType?: ReinsuranceDocumentType;
46+
fileName?: string;
3647
}) {
3748
const [hasImage, setHasImage] = useState(false);
3849
const Glyph = glyphFor(documentType);
50+
const canRenderPage = rendersPage(fileName);
3951

4052
return (
4153
<span className="relative flex h-12 w-[2.375rem] shrink-0 items-center justify-center overflow-hidden rounded-md border border-border bg-surface-2 text-subtle-foreground shadow-soft ring-1 ring-inset ring-border/40 transition-[border-color,box-shadow] group-hover:border-border-strong group-hover:shadow-pop">
@@ -44,19 +56,23 @@ export function QueueThumbnail({
4456
<Glyph width={15} height={15} />
4557
</span>
4658
)}
47-
{/* eslint-disable-next-line @next/next/no-img-element */}
48-
<img
49-
src={api.pageImageUrl(documentId, 1)}
50-
alt=""
51-
aria-hidden="true"
52-
loading="lazy"
53-
onLoad={() => setHasImage(true)}
54-
onError={() => setHasImage(false)}
55-
className={cn(
56-
"absolute inset-0 h-full w-full object-cover object-top transition-opacity duration-300",
57-
hasImage ? "opacity-100" : "opacity-0",
58-
)}
59-
/>
59+
{canRenderPage && (
60+
<>
61+
{/* eslint-disable-next-line @next/next/no-img-element */}
62+
<img
63+
src={api.pageImageUrl(documentId, 1)}
64+
alt=""
65+
aria-hidden="true"
66+
loading="lazy"
67+
onLoad={() => setHasImage(true)}
68+
onError={() => setHasImage(false)}
69+
className={cn(
70+
"absolute inset-0 h-full w-full object-cover object-top transition-opacity duration-300",
71+
hasImage ? "opacity-100" : "opacity-0",
72+
)}
73+
/>
74+
</>
75+
)}
6076
{/* A faint top sheen sells the thumbnail as a real page edge, not a flat box. */}
6177
{hasImage && (
6278
<span

web/components/workspace/work-queue.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function QueueRow({ document }: { document: DocumentSummary }) {
2727
className="absolute inset-y-0 left-0 w-0.5 origin-center scale-y-0 bg-primary transition-transform duration-200 ease-out group-hover:scale-y-100 group-focus-visible:scale-y-100"
2828
/>
2929
<div className="flex min-w-0 items-center gap-3.5">
30-
<QueueThumbnail documentId={document.id} documentType={document.documentType} />
30+
<QueueThumbnail documentId={document.id} documentType={document.documentType} fileName={document.fileName} />
3131
<span className="flex min-w-0 flex-col gap-1">
3232
<span className="truncate text-sm font-medium tracking-tight text-foreground/90 transition-colors group-hover:text-foreground">
3333
{document.fileName}

0 commit comments

Comments
 (0)