overleaf-cep/services/web/modules/full-project-search/frontend/js/components/full-project-match-counts.tsx
Andrew Rumble 519b18e4a1 Lint fixes
GitOrigin-RevId: 686f3fb718faf5830a34656d45f888c8e245f7f9
2025-07-09 08:05:48 +00:00

32 lines
840 B
TypeScript

import React, { FC } from 'react'
import LoadingSpinner from '@/shared/components/loading-spinner'
import { MatchedFile } from '../util/search-snapshot'
import { useTranslation } from 'react-i18next'
export const FullProjectMatchCounts: FC<{
loading: boolean
matchedFiles?: MatchedFile[]
}> = ({ loading, matchedFiles }) => {
const { t } = useTranslation()
if (loading) {
return <LoadingSpinner delay={500} />
}
if (matchedFiles === undefined) {
return null
}
const totalResults = matchedFiles.flatMap(file => file.hits).length
if (totalResults === 0) {
return <>{t('project_search_result_count', { count: totalResults })}</>
}
return (
<>
{t('project_search_result_count', { count: totalResults })}{' '}
{t('project_search_file_count', { count: matchedFiles.length })}
</>
)
}