import { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { useTranslation } from 'react-i18next'; import { ChevronDown, ChevronUp, FileText } from 'lucide-react'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import { api } from '../api/client'; interface FolderReadmePanelProps { folderId: number; } /** * Side panel that renders a `.md` file from the selected folder (#1268). * Hidden when the folder has no markdown file. Disables raw HTML and links * stay text-only — same posture as the print-archive note panel. */ export function FolderReadmePanel({ folderId }: FolderReadmePanelProps) { const { t } = useTranslation(); const [collapsed, setCollapsed] = useState(false); const { data, isLoading, error } = useQuery({ queryKey: ['folder-readme', folderId], queryFn: () => api.getLibraryFolderReadme(folderId), retry: false, staleTime: 30_000, }); if (isLoading || error || !data) return null; return (
{!collapsed && (

{children}

, h2: ({ children }) =>

{children}

, h3: ({ children }) =>

{children}

, p: ({ children }) =>

{children}

, ul: ({ children }) =>
    {children}
, ol: ({ children }) =>
    {children}
, li: ({ children }) =>
  • {children}
  • , code: ({ children, ...props }) => { const inline = !(props as { className?: string }).className; return inline ? ( {children} ) : ( {children} ); }, pre: ({ children }) =>
    {children}
    , blockquote: ({ children }) => (
    {children}
    ), a: ({ children, href }) => ( {children} ), table: ({ children }) => (
    {children}
    ), th: ({ children }) => {children}, td: ({ children }) => {children}, hr: () =>
    , }} > {data.content}
    )}
    ); }