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.

906 B
Raw Blame
'use client';

import { Center, Empty } from '@lobehub/ui';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';

import FileViewer from '@/features/FileViewer';
import ImageEditTools from '@/features/FileViewer/ImageEditTools';
import { type FileListItem } from '@/types/files';

interface FilePreviewProps {
  file: FileListItem;
}

/**
 * Live preview of the selected resource inside the detail panel. Falls back
 * to a neutral hint for types the FileViewer cannot render.
 */
const FilePreview = memo<FilePreviewProps>(({ file }) => {
  const { t } = useTranslation('file');

  if (!file?.url)
    return (
      <Center height={'100%'} width={'100%'}>
        <Empty description={t('preview.unsupportedFileAndContact')} />
      </Center>
    );

  return <FileViewer {...file} id={file.fileId ?? file.id} imageTools={<ImageEditTools />} />;
});

export default FilePreview;