PagePathNav.tsx 2.3 KB

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