full-project-match-counts.tsx 864 B

123456789101112131415161718192021222324252627282930313233
  1. import React, { FC } from 'react'
  2. import LoadingSpinner from '@/shared/components/loading-spinner'
  3. import { MatchedFile } from '../util/search-snapshot'
  4. import { useTranslation } from 'react-i18next'
  5. export const FullProjectMatchCounts: FC<{
  6. loading: boolean
  7. totalResults?: number
  8. matchedFiles?: MatchedFile[]
  9. }> = ({ loading, matchedFiles }) => {
  10. const { t } = useTranslation()
  11. if (loading) {
  12. return <LoadingSpinner delay={500} />
  13. }
  14. if (matchedFiles === undefined) {
  15. return null
  16. }
  17. const totalResults = matchedFiles.flatMap(file => file.hits).length
  18. if (totalResults === 0) {
  19. return <>{t('project_search_result_count', { count: totalResults })}</>
  20. }
  21. return (
  22. <>
  23. {t('project_search_result_count', { count: totalResults })}{' '}
  24. {t('project_search_file_count', { count: matchedFiles.length })}
  25. </>
  26. )
  27. }