out-of-sync-modal.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { Trans, useTranslation } from 'react-i18next'
  2. import { memo, useState } from 'react'
  3. import { useLocation } from '@/shared/hooks/use-location'
  4. import OLButton from '@/shared/components/ol/ol-button'
  5. import {
  6. OLModal,
  7. OLModalBody,
  8. OLModalFooter,
  9. OLModalHeader,
  10. OLModalTitle,
  11. } from '@/shared/components/ol/ol-modal'
  12. export type OutOfSyncModalProps = {
  13. editorContent: string
  14. show: boolean
  15. onHide: () => void
  16. }
  17. function OutOfSyncModal({ editorContent, show, onHide }: OutOfSyncModalProps) {
  18. const { t } = useTranslation()
  19. const location = useLocation()
  20. const [editorContentShown, setEditorContentShown] = useState(false)
  21. const editorContentRows = (editorContent.match(/\n/g)?.length || 0) + 1
  22. // Reload the page to avoid staying in an inconsistent state.
  23. // https://github.com/overleaf/issues/issues/3694
  24. function done() {
  25. onHide()
  26. location.reload()
  27. }
  28. return (
  29. <OLModal
  30. show={show}
  31. onHide={done}
  32. className="out-of-sync-modal"
  33. backdrop={false}
  34. keyboard={false}
  35. >
  36. <OLModalHeader>
  37. <OLModalTitle>{t('out_of_sync')}</OLModalTitle>
  38. </OLModalHeader>
  39. <OLModalBody className="modal-body-share">
  40. <Trans
  41. i18nKey="out_of_sync_detail"
  42. components={[
  43. // eslint-disable-next-line react/jsx-key
  44. <br />,
  45. // eslint-disable-next-line jsx-a11y/anchor-has-content,react/jsx-key
  46. <a
  47. target="_blank"
  48. rel="noopener noreferrer"
  49. href="/learn/Kb/Editor_out_of_sync_problems"
  50. />,
  51. ]}
  52. />
  53. </OLModalBody>
  54. <OLModalBody>
  55. <OLButton
  56. variant="secondary"
  57. onClick={() => setEditorContentShown(shown => !shown)}
  58. >
  59. {editorContentShown
  60. ? t('hide_local_file_contents')
  61. : t('show_local_file_contents')}
  62. </OLButton>
  63. {editorContentShown ? (
  64. <div className="text-preview">
  65. <textarea
  66. className="scroll-container"
  67. readOnly
  68. rows={editorContentRows}
  69. value={editorContent}
  70. />
  71. </div>
  72. ) : null}
  73. </OLModalBody>
  74. <OLModalFooter>
  75. <OLButton variant="secondary" onClick={done}>
  76. {t('reload_editor')}
  77. </OLButton>
  78. </OLModalFooter>
  79. </OLModal>
  80. )
  81. }
  82. export default memo(OutOfSyncModal)