preview-logs-pane-max-entries.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { useCallback } from 'react'
  2. import { Trans, useTranslation } from 'react-i18next'
  3. import OLButton from '@/shared/components/ol/ol-button'
  4. import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
  5. import { useStopOnFirstError } from '../../../shared/hooks/use-stop-on-first-error'
  6. import MaterialIcon from '@/shared/components/material-icon'
  7. import PdfLogEntry from '@/features/pdf-preview/components/pdf-log-entry'
  8. function PreviewLogsPaneMaxEntries({
  9. totalEntries,
  10. entriesShown,
  11. hasErrors,
  12. }: {
  13. totalEntries: number
  14. entriesShown: number
  15. hasErrors?: boolean
  16. }) {
  17. const { t } = useTranslation()
  18. const title = t('log_entry_maximum_entries_title', {
  19. total: totalEntries,
  20. displayed: entriesShown,
  21. })
  22. return (
  23. <PdfLogEntry
  24. entryAriaLabel={t('log_entry_maximum_entries')}
  25. headerTitle={title}
  26. level="raw"
  27. formattedContent={
  28. <PreviewLogsPaneMaxEntriesContent hasErrors={hasErrors} />
  29. }
  30. />
  31. )
  32. }
  33. function PreviewLogsPaneMaxEntriesContent({
  34. hasErrors,
  35. }: {
  36. hasErrors?: boolean
  37. }) {
  38. const { t } = useTranslation()
  39. const { startCompile, stoppedOnFirstError, setAnimateCompileDropdownArrow } =
  40. useCompileContext()
  41. const { enableStopOnFirstError } = useStopOnFirstError({
  42. eventSource: 'too-many-logs',
  43. })
  44. const handleEnableStopOnFirstErrorClick = useCallback(() => {
  45. enableStopOnFirstError()
  46. startCompile({ stopOnFirstError: true })
  47. setAnimateCompileDropdownArrow(true)
  48. }, [enableStopOnFirstError, startCompile, setAnimateCompileDropdownArrow])
  49. if (hasErrors && !stoppedOnFirstError) {
  50. return (
  51. <>
  52. <p>
  53. <MaterialIcon type="lightbulb" className="align-middle" />
  54. &nbsp;
  55. <strong>{t('tip')}: </strong>
  56. <Trans
  57. i18nKey="log_entry_maximum_entries_enable_stop_on_first_error"
  58. components={[
  59. <OLButton
  60. variant="primary"
  61. size="sm"
  62. key="enable-stop-on-first-error"
  63. onClick={handleEnableStopOnFirstErrorClick}
  64. />,
  65. // eslint-disable-next-line jsx-a11y/anchor-has-content
  66. <a
  67. key="learn-more"
  68. href="https://www.overleaf.com/learn/latex/Questions/Tips_and_Tricks_for_Troubleshooting_LaTeX"
  69. />,
  70. ]}
  71. />{' '}
  72. </p>
  73. <p>{t('log_entry_maximum_entries_see_full_logs')}</p>
  74. </>
  75. )
  76. }
  77. return (
  78. <p>
  79. <MaterialIcon type="lightbulb" className="align-middle" />
  80. &nbsp;
  81. <strong>{t('tip')}: </strong>
  82. {t('log_entry_maximum_entries_see_full_logs')}
  83. </p>
  84. )
  85. }
  86. export default PreviewLogsPaneMaxEntries