SidebarContents.jsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import { withUnstatedContainers } from '../UnstatedUtils';
  5. import NavigationContainer from '~/client/services/NavigationContainer';
  6. import { useTargetAndAncestors } from '../../stores/context';
  7. import RecentChanges from './RecentChanges';
  8. import CustomSidebar from './CustomSidebar';
  9. import PageTree from './PageTree';
  10. const SidebarContents = (props) => {
  11. const { navigationContainer, isSharedUser } = props;
  12. const pageContainer = navigationContainer.getPageContainer();
  13. const { targetAndAncestors } = pageContainer.state;
  14. useTargetAndAncestors(targetAndAncestors);
  15. if (isSharedUser) {
  16. return null;
  17. }
  18. let Contents;
  19. switch (navigationContainer.state.sidebarContentsId) {
  20. case 'recent':
  21. Contents = RecentChanges;
  22. break;
  23. case 'tree':
  24. Contents = PageTree;
  25. break;
  26. default:
  27. Contents = CustomSidebar;
  28. }
  29. return (
  30. <Contents />
  31. );
  32. };
  33. SidebarContents.propTypes = {
  34. navigationContainer: PropTypes.instanceOf(NavigationContainer).isRequired,
  35. isSharedUser: PropTypes.bool,
  36. };
  37. SidebarContents.defaultProps = {
  38. isSharedUser: false,
  39. };
  40. /**
  41. * Wrapper component for using unstated
  42. */
  43. const SidebarContentsWrapper = withUnstatedContainers(SidebarContents, [NavigationContainer]);
  44. export default withTranslation()(SidebarContentsWrapper);