DisplaySwitcher.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import React, { useMemo } from 'react';
  2. import { pagePathUtils } from '@growi/core';
  3. import { useTranslation } from 'next-i18next';
  4. import dynamic from 'next/dynamic';
  5. import { TabContent, TabPane } from 'reactstrap';
  6. import { smoothScrollIntoView } from '~/client/util/smooth-scroll';
  7. import { isPopulated } from '~/interfaces/common';
  8. import {
  9. useCurrentPagePath, useIsSharedUser, useIsEditable, useIsUserPage, usePageUser, useShareLinkId, useIsNotFound,
  10. } from '~/stores/context';
  11. import { useDescendantsPageListModal } from '~/stores/modal';
  12. import { useSWRxCurrentPage } from '~/stores/page';
  13. import { EditorMode, useEditorMode } from '~/stores/ui';
  14. import CountBadge from '../Common/CountBadge';
  15. import ContentLinkButtons from '../ContentLinkButtons';
  16. import PageListIcon from '../Icons/PageListIcon';
  17. import NotFoundPage from '../NotFoundPage';
  18. // import Page from '../Page';
  19. // import PageEditor from '../PageEditor';
  20. // import PageEditorByHackmd from '../PageEditorByHackmd';
  21. import TableOfContents from '../TableOfContents';
  22. import UserInfo from '../User/UserInfo';
  23. const WIKI_HEADER_LINK = 120;
  24. const { isTopPage } = pagePathUtils;
  25. const DisplaySwitcher = (): JSX.Element => {
  26. const { t } = useTranslation();
  27. const EditorNavbarBottom = dynamic(() => import('../PageEditor/EditorNavbarBottom'), { ssr: false });
  28. const HashChanged = dynamic(() => import('../EventListeneres/HashChanged'), { ssr: false });
  29. // get element for smoothScroll
  30. // const getCommentListDom = useMemo(() => { return document.getElementById('page-comments-list') }, []);
  31. const { data: currentPagePath } = useCurrentPagePath();
  32. const { data: isSharedUser } = useIsSharedUser();
  33. const { data: shareLinkId } = useShareLinkId();
  34. const { data: isUserPage } = useIsUserPage();
  35. const { data: isEditable } = useIsEditable();
  36. const { data: pageUser } = usePageUser();
  37. const { data: isNotFound } = useIsNotFound();
  38. const { data: currentPage } = useSWRxCurrentPage(shareLinkId ?? undefined);
  39. const { data: editorMode } = useEditorMode();
  40. const { open: openDescendantPageListModal } = useDescendantsPageListModal();
  41. const isViewMode = editorMode === EditorMode.View;
  42. const isTopPagePath = isTopPage(currentPagePath ?? '');
  43. const revision = currentPage?.revision;
  44. return (
  45. <>
  46. <TabContent activeTab={editorMode}>
  47. <TabPane tabId={EditorMode.View}>
  48. <div className="d-flex flex-column flex-lg-row-reverse">
  49. { !isNotFound && !currentPage?.isEmpty && (
  50. <div className="grw-side-contents-container">
  51. <div className="grw-side-contents-sticky-container">
  52. {/* Page list */}
  53. <div className="grw-page-accessories-control">
  54. { currentPagePath != null && !isSharedUser && (
  55. <button
  56. type="button"
  57. className="btn btn-block btn-outline-secondary grw-btn-page-accessories rounded-pill d-flex justify-content-between align-items-center"
  58. onClick={() => openDescendantPageListModal(currentPagePath)}
  59. >
  60. <div className="grw-page-accessories-control-icon">
  61. <PageListIcon />
  62. </div>
  63. {t('page_list')}
  64. <CountBadge count={currentPage?.descendantCount} offset={1} />
  65. </button>
  66. ) }
  67. </div>
  68. {/* Comments */}
  69. {/* { getCommentListDom != null && !isTopPagePath && ( */}
  70. { !isTopPagePath && (
  71. <div className="grw-page-accessories-control mt-2">
  72. <button
  73. type="button"
  74. className="btn btn-block btn-outline-secondary grw-btn-page-accessories rounded-pill d-flex justify-content-between align-items-center"
  75. // onClick={() => smoothScrollIntoView(getCommentListDom, WIKI_HEADER_LINK)}
  76. >
  77. <i className="icon-fw icon-bubbles grw-page-accessories-control-icon"></i>
  78. <span>Comments</span>
  79. <CountBadge count={currentPage?.commentCount} />
  80. </button>
  81. </div>
  82. ) }
  83. <div className="d-none d-lg-block">
  84. <div id="revision-toc" className="revision-toc">
  85. {/* <TableOfContents /> */}
  86. </div>
  87. <ContentLinkButtons />
  88. </div>
  89. </div>
  90. </div>
  91. ) }
  92. <div className="flex-grow-1 flex-basis-0 mw-0">
  93. { isUserPage && <UserInfo pageUser={pageUser} />}
  94. {/* { !isNotFound && <Page /> } */}
  95. { !isNotFound && revision != null && isPopulated(revision) && revision.body }
  96. { isNotFound && <NotFoundPage /> }
  97. </div>
  98. </div>
  99. </TabPane>
  100. { isEditable && (
  101. <TabPane tabId={EditorMode.Editor}>
  102. <div data-testid="page-editor" id="page-editor">
  103. {/* <PageEditor /> */}
  104. </div>
  105. </TabPane>
  106. ) }
  107. { isEditable && (
  108. <TabPane tabId={EditorMode.HackMD}>
  109. <div id="page-editor-with-hackmd">
  110. {/* <PageEditorByHackmd /> */}
  111. </div>
  112. </TabPane>
  113. ) }
  114. </TabContent>
  115. { isEditable && !isViewMode && <EditorNavbarBottom /> }
  116. { isEditable && <HashChanged></HashChanged> }
  117. </>
  118. );
  119. };
  120. export default DisplaySwitcher;