editor-left-menu.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { useLayoutContext } from '../../../shared/context/layout-context'
  2. import LeftMenuMask from './left-menu-mask'
  3. import AccessibleModal from '../../../shared/components/accessible-modal'
  4. import { Modal } from 'react-bootstrap'
  5. import classNames from 'classnames'
  6. import { lazy, memo, Suspense } from 'react'
  7. import { FullSizeLoadingSpinner } from '@/shared/components/loading-spinner'
  8. import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
  9. import { Offcanvas } from 'react-bootstrap-5'
  10. import { EditorLeftMenuProvider } from './editor-left-menu-context'
  11. import withErrorBoundary from '@/infrastructure/error-boundary'
  12. import OLNotification from '@/features/ui/components/ol/ol-notification'
  13. import { useTranslation } from 'react-i18next'
  14. const EditorLeftMenuBody = lazy(() => import('./editor-left-menu-body'))
  15. const LazyEditorLeftMenuWithErrorBoundary = withErrorBoundary(
  16. () => (
  17. <Suspense fallback={<FullSizeLoadingSpinner delay={500} />}>
  18. <EditorLeftMenuBody />
  19. </Suspense>
  20. ),
  21. () => {
  22. const { t } = useTranslation()
  23. return <OLNotification type="error" content={t('something_went_wrong')} />
  24. }
  25. )
  26. function EditorLeftMenu() {
  27. const { leftMenuShown, setLeftMenuShown } = useLayoutContext()
  28. const closeLeftMenu = () => {
  29. setLeftMenuShown(false)
  30. }
  31. return (
  32. <BootstrapVersionSwitcher
  33. bs3={
  34. <EditorLeftMenuProvider>
  35. <AccessibleModal
  36. backdropClassName="left-menu-modal-backdrop"
  37. keyboard
  38. onHide={closeLeftMenu}
  39. id="left-menu-modal"
  40. show={leftMenuShown}
  41. >
  42. <Modal.Body
  43. className={classNames('full-size', { shown: leftMenuShown })}
  44. id="left-menu"
  45. >
  46. <Suspense fallback={<FullSizeLoadingSpinner delay={500} />}>
  47. <EditorLeftMenuBody />
  48. </Suspense>
  49. </Modal.Body>
  50. </AccessibleModal>
  51. {leftMenuShown && <LeftMenuMask />}
  52. </EditorLeftMenuProvider>
  53. }
  54. bs5={
  55. <EditorLeftMenuProvider>
  56. <Offcanvas
  57. show={leftMenuShown}
  58. onHide={closeLeftMenu}
  59. backdropClassName="left-menu-modal-backdrop"
  60. id="left-menu-offcanvas"
  61. >
  62. <Offcanvas.Body
  63. className={classNames('full-size', 'left-menu', {
  64. shown: leftMenuShown,
  65. })}
  66. id="left-menu"
  67. >
  68. <LazyEditorLeftMenuWithErrorBoundary />
  69. </Offcanvas.Body>
  70. </Offcanvas>
  71. {leftMenuShown && <LeftMenuMask />}
  72. </EditorLeftMenuProvider>
  73. }
  74. />
  75. )
  76. }
  77. export default memo(EditorLeftMenu)