diff --git a/apps/web/components/new/document-cards/file-preview.tsx b/apps/web/components/new/document-cards/file-preview.tsx index d8943db4..cb2ce4f4 100644 --- a/apps/web/components/new/document-cards/file-preview.tsx +++ b/apps/web/components/new/document-cards/file-preview.tsx @@ -1,5 +1,6 @@ "use client" +import { useState } from "react" import type { DocumentsWithMemoriesResponseSchema } from "@repo/validation/api" import type { z } from "zod" import { dmSansClassName } from "@/utils/fonts" @@ -69,10 +70,15 @@ function getFileTypeInfo(document: DocumentWithMemories): { } export function FilePreview({ document }: { document: DocumentWithMemories }) { + const [imageError, setImageError] = useState(false) const { icon, extension, color } = getFileTypeInfo(document) + + const type = document.type?.toLowerCase() + const mimeType = document.metadata?.mimeType as string | undefined + const isImage = (mimeType?.startsWith("image/") || type === "image") && document.url && !imageError return ( -
+
{color && (
)} -
- {icon} -

- {extension} -

-
- {document.content && ( -

- {document.content} -

+ {isImage ? ( + <> +
+ {document.title setImageError(true)} + loading="lazy" + /> +
+ {document.content && ( +
+

+ {document.content} +

+
+ )} + + ) : ( +
+
+ {icon} +

+ {extension} +

+
+ {document.content && ( +

+ {document.content} +

+ )} +
)}
)