editor-left-menu.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { useLayoutContext } from '../../../shared/context/layout-context'
  2. import LeftMenuMask from './left-menu-mask'
  3. import classNames from 'classnames'
  4. import { lazy, memo, Suspense } from 'react'
  5. import { FullSizeLoadingSpinner } from '@/shared/components/loading-spinner'
  6. import { Offcanvas } from 'react-bootstrap'
  7. import { EditorLeftMenuProvider } from './editor-left-menu-context'
  8. import withErrorBoundary from '@/infrastructure/error-boundary'
  9. import OLNotification from '@/features/ui/components/ol/ol-notification'
  10. import { useTranslation } from 'react-i18next'
  11. const EditorLeftMenuBody = lazy(() => import('./editor-left-menu-body'))
  12. const LazyEditorLeftMenuWithErrorBoundary = withErrorBoundary(
  13. () => (
  14. <Suspense fallback={<FullSizeLoadingSpinner delay={500} />}>
  15. <EditorLeftMenuBody />
  16. </Suspense>
  17. ),
  18. () => {
  19. const { t } = useTranslation()
  20. return <OLNotification type="error" content={t('something_went_wrong')} />
  21. }
  22. )
  23. function EditorLeftMenu() {
  24. const { leftMenuShown, setLeftMenuShown } = useLayoutContext()
  25. const closeLeftMenu = () => {
  26. setLeftMenuShown(false)
  27. }
  28. return (
  29. <EditorLeftMenuProvider>
  30. <Offcanvas
  31. show={leftMenuShown}
  32. onHide={closeLeftMenu}
  33. backdropClassName="left-menu-modal-backdrop"
  34. id="left-menu-offcanvas"
  35. >
  36. <Offcanvas.Body
  37. className={classNames('full-size', 'left-menu', {
  38. shown: leftMenuShown,
  39. })}
  40. id="left-menu"
  41. data-testid="left-menu"
  42. >
  43. <LazyEditorLeftMenuWithErrorBoundary />
  44. </Offcanvas.Body>
  45. </Offcanvas>
  46. {leftMenuShown && <LeftMenuMask />}
  47. </EditorLeftMenuProvider>
  48. )
  49. }
  50. export default memo(EditorLeftMenu)