out-of-sync-modal.tsx 2.4 KB

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