Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.1 KB
Raw Blame
'use client';

import { Center, Empty, Flexbox, Markdown, Skeleton } from '@lobehub/ui';
import { memo } from 'react';

import { useDocumentStore } from '@/store/document';

interface PagePreviewProps {
  id: string;
}

/**
 * Read-only preview of a page (文稿) inside the detail panel. Pages carry no
 * file URL, so render the document's Markdown content instead of FileViewer.
 */
const PagePreview = memo<PagePreviewProps>(({ id }) => {
  const useFetchDocumentDetail = useDocumentStore((s) => s.useFetchDocumentDetail);
  const { data: document, isHydrated, isLoading } = useFetchDocumentDetail(id);

  if (isLoading && !isHydrated) return null;
  if (isLoading)
    return (
      <Flexbox padding={24}>
        <Skeleton.Text rows={6} width={['60%', '90%', '80%', '85%', '70%', '40%']} />
      </Flexbox>
    );

  if (!document?.content)
    return (
      <Center height={'100%'} width={'100%'}>
        <Empty />
      </Center>
    );

  return (
    <Flexbox paddingBlock={16} paddingInline={24}>
      <Markdown variant={'chat'}>{document.content}</Markdown>
    </Flexbox>
  );
});

PagePreview.displayName = 'PagePreview';

export default PagePreview;