PagePathNav.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import React, { FC } from 'react';
  2. import { DevidedPagePath, pagePathUtils } from '@growi/core';
  3. import dynamic from 'next/dynamic';
  4. import { useIsNotFound } from '~/stores/context';
  5. import LinkedPagePath from '../models/linked-page-path';
  6. const { isTrashPage } = pagePathUtils;
  7. type Props = {
  8. pagePath: string,
  9. pageId?: string | null,
  10. isSingleLineMode?:boolean,
  11. isCompactMode?:boolean,
  12. }
  13. const CopyDropdown = dynamic(() => import('./Page/CopyDropdown'), { ssr: false });
  14. const PagePathHierarchicalLink = dynamic(() => import('./PagePathHierarchicalLink'), { ssr: false });
  15. const PagePathNav: FC<Props> = (props: Props) => {
  16. const {
  17. pageId, pagePath, isSingleLineMode, isCompactMode,
  18. } = props;
  19. const dPagePath = new DevidedPagePath(pagePath, false, true);
  20. const { data: isNotFound } = useIsNotFound();
  21. const isInTrash = isTrashPage(pagePath);
  22. let formerLink;
  23. let latterLink;
  24. // one line
  25. if (dPagePath.isRoot || dPagePath.isFormerRoot || isSingleLineMode) {
  26. const linkedPagePath = new LinkedPagePath(pagePath);
  27. latterLink = <PagePathHierarchicalLink linkedPagePath={linkedPagePath} isInTrash={isInTrash} />;
  28. }
  29. // two line
  30. else {
  31. const linkedPagePathFormer = new LinkedPagePath(dPagePath.former);
  32. const linkedPagePathLatter = new LinkedPagePath(dPagePath.latter);
  33. formerLink = <PagePathHierarchicalLink linkedPagePath={linkedPagePathFormer} isInTrash={isInTrash} />;
  34. latterLink = <PagePathHierarchicalLink linkedPagePath={linkedPagePathLatter} basePath={dPagePath.former} isInTrash={isInTrash} />;
  35. }
  36. const copyDropdownId = `copydropdown${isCompactMode ? '-subnav-compact' : ''}-${pageId}`;
  37. const copyDropdownToggleClassName = 'd-block btn-outline-secondary btn-copy border-0 text-muted p-2';
  38. return (
  39. <div className="grw-page-path-nav">
  40. {formerLink}
  41. <span className="d-flex align-items-center">
  42. <h1 className="m-0">{latterLink}</h1>
  43. { pageId != null && !isNotFound && (
  44. <div className="mx-2">
  45. <CopyDropdown pageId={pageId} pagePath={pagePath} dropdownToggleId={copyDropdownId} dropdownToggleClassName={copyDropdownToggleClassName}>
  46. <i className="ti ti-clipboard"></i>
  47. </CopyDropdown>
  48. </div>
  49. ) }
  50. </span>
  51. </div>
  52. );
  53. };
  54. export default PagePathNav;