2
0

PagePathNav.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import React, { FC } from 'react';
  2. import { DevidedPagePath, pagePathUtils } from '@growi/core';
  3. import dynamic from 'next/dynamic';
  4. import { useIsNotFound } from '~/stores/page';
  5. import LinkedPagePath from '../models/linked-page-path';
  6. import PagePathHierarchicalLink from './PagePathHierarchicalLink';
  7. const { isTrashPage } = pagePathUtils;
  8. type Props = {
  9. pagePath: string,
  10. pageId?: string | null,
  11. isSingleLineMode?:boolean,
  12. isCompactMode?:boolean,
  13. }
  14. const CopyDropdown = dynamic(() => import('./Page/CopyDropdown'), { 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. <div 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. </div>
  51. </div>
  52. );
  53. };
  54. export default PagePathNav;