import { DocumentsProps } from '../models/misc'; import Trash from '../assets/trash.svg'; import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next'; // Utility function to format numbers const formatTokens = (tokens: number): string => { const roundToTwoDecimals = (num: number): string => { return (Math.round((num + Number.EPSILON) * 100) / 100).toString(); }; if (tokens >= 1_000_000_000) { return roundToTwoDecimals(tokens / 1_000_000_000) + 'b'; } else if (tokens >= 1_000_000) { return roundToTwoDecimals(tokens / 1_000_000) + 'm'; } else if (tokens >= 1_000) { return roundToTwoDecimals(tokens / 1_000) + 'k'; } else { return tokens.toString(); } }; const Documents: React.FC = ({ documents, handleDeleteDocument, }) => { const { t } = useTranslation(); return (
{documents && documents.map((document, index) => ( ))}
{t('settings.documents.name')} {t('settings.documents.date')} {t('settings.documents.tokenUsage')} {t('settings.documents.type')}
{document.name} {document.date} {document.tokens ? formatTokens(+document.tokens) : ''} {document.location === 'remote' ? 'Pre-loaded' : 'Private'} {document.location !== 'remote' && ( Delete { event.stopPropagation(); handleDeleteDocument(index, document); }} /> )}
); }; Documents.propTypes = { documents: PropTypes.array.isRequired, handleDeleteDocument: PropTypes.func.isRequired, }; export default Documents;