full-project-match-counts.tsx 840 B

1234567891011121314151617181920212223242526272829303132
  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. matchedFiles?: MatchedFile[]
  8. }> = ({ loading, matchedFiles }) => {
  9. const { t } = useTranslation()
  10. if (loading) {
  11. return <LoadingSpinner delay={500} />
  12. }
  13. if (matchedFiles === undefined) {
  14. return null
  15. }
  16. const totalResults = matchedFiles.flatMap(file => file.hits).length
  17. if (totalResults === 0) {
  18. return <>{t('project_search_result_count', { count: totalResults })}</>
  19. }
  20. return (
  21. <>
  22. {t('project_search_result_count', { count: totalResults })}{' '}
  23. {t('project_search_file_count', { count: matchedFiles.length })}
  24. </>
  25. )
  26. }