"use client" import type { DocumentsWithMemoriesResponseSchema } from "@repo/validation/api" import type { z } from "zod" import dynamic from "next/dynamic" import { isTwitterUrl } from "@/lib/url-helpers" import { ImagePreview } from "./image-preview" import { TweetContent } from "./tweet" import { NotionDoc } from "./notion-doc" import { YoutubeVideo } from "./yt-video" import { WebPageContent } from "./web-page" import { TextEditorContent } from "./text-editor-content" import { GoogleDocViewer } from "./google-doc" import type { TextEditorProps } from "./text-editor-content" export type { TextEditorProps } const PdfViewer = dynamic( () => import("./pdf").then((mod) => ({ default: mod.PdfViewer })), { ssr: false, loading: () => (
Loading PDF viewer...
), }, ) as typeof import("./pdf").PdfViewer type DocumentsResponse = z.infer type DocumentWithMemories = DocumentsResponse["documents"][0] interface DocumentContentProps { document: DocumentWithMemories | null textEditorProps: TextEditorProps } type ContentType = | "image" | "tweet" | "text" | "pdf" | "notion" | "youtube" | "webpage" | "google_doc" | "google_sheet" | "google_slide" | null function getContentType(document: DocumentWithMemories | null): ContentType { if (!document) return null const isImage = document.type === "image" || document.metadata?.mimeType?.toString().startsWith("image/") if (isImage && document.url) return "image" if (document.type === "tweet" || (document.url && isTwitterUrl(document.url))) return "tweet" if (document.type === "text") return "text" if (document.type === "pdf") return "pdf" if (document.type === "notion_doc") return "notion" if (document.type === "google_doc") return "google_doc" if (document.type === "google_sheet") return "google_sheet" if (document.type === "google_slide") return "google_slide" if (document.url?.includes("youtube.com")) return "youtube" if (document.type === "webpage") return "webpage" return null } export function DocumentContent({ document, textEditorProps, }: DocumentContentProps) { const contentType = getContentType(document) if (!document || !contentType) return null switch (contentType) { case "image": return case "tweet": return ( ) case "text": return case "pdf": return case "notion": return case "youtube": return case "webpage": return case "google_doc": return ( ) case "google_sheet": return ( ) case "google_slide": return ( ) default: return null } }