"use client"; import { useEffect, useState } from "react"; import { z } from "zod"; import { Schema_File } from "~/schema"; import { cn } from "~/utils"; import Icon from "~/components/Icon"; import { Button } from "~/components/ui/button"; import Markdown from "./@markdown"; import { GetContent } from "./actions"; type Props = { file: z.infer; view: "markdown" | "raw"; code?: boolean; }; export default function PreviewRich({ file, code, view }: Props) { const [fetchedContent, setFetchedContent] = useState(""); const [content, setContent] = useState(""); const [loading, setLoading] = useState(true); const [error, setError] = useState(""); const [expand, setExpand] = useState(false); useEffect(() => { (async () => { try { const text = await GetContent(file.encryptedId); if (!text) { setError("Looks like there is no content to preview"); return; } // setFetchedContent(text); // if (code) { // setContent(`\`\`\`${file.fileExtension}\n${text}\`\`\``); // } else { setContent(text.trim()); // } } catch (error) { const e = error as Error; console.error(e); setError(e.message); } finally { setLoading(false); } })(); }, [file, code]); return (
{loading ? (

Loading content...

) : error ? (
{error}
) : (
)}
); }