import React, { useMemo } from 'react'; import { pagePathUtils } from '@growi/core'; import { useTranslation } from 'next-i18next'; import dynamic from 'next/dynamic'; import { TabContent, TabPane } from 'reactstrap'; import { smoothScrollIntoView } from '~/client/util/smooth-scroll'; import { isPopulated } from '~/interfaces/common'; import { useCurrentPagePath, useIsSharedUser, useIsEditable, useIsUserPage, usePageUser, useShareLinkId, useIsNotFound, } from '~/stores/context'; import { useDescendantsPageListModal } from '~/stores/modal'; import { useSWRxCurrentPage } from '~/stores/page'; import { EditorMode, useEditorMode } from '~/stores/ui'; import CountBadge from '../Common/CountBadge'; import ContentLinkButtons from '../ContentLinkButtons'; import PageListIcon from '../Icons/PageListIcon'; import NotFoundPage from '../NotFoundPage'; // import Page from '../Page'; // import PageEditor from '../PageEditor'; // import PageEditorByHackmd from '../PageEditorByHackmd'; import TableOfContents from '../TableOfContents'; import UserInfo from '../User/UserInfo'; const WIKI_HEADER_LINK = 120; const { isTopPage } = pagePathUtils; const DisplaySwitcher = (): JSX.Element => { const { t } = useTranslation(); const EditorNavbarBottom = dynamic(() => import('../PageEditor/EditorNavbarBottom'), { ssr: false }); const HashChanged = dynamic(() => import('../EventListeneres/HashChanged'), { ssr: false }); // get element for smoothScroll // const getCommentListDom = useMemo(() => { return document.getElementById('page-comments-list') }, []); const { data: currentPagePath } = useCurrentPagePath(); const { data: isSharedUser } = useIsSharedUser(); const { data: shareLinkId } = useShareLinkId(); const { data: isUserPage } = useIsUserPage(); const { data: isEditable } = useIsEditable(); const { data: pageUser } = usePageUser(); const { data: isNotFound } = useIsNotFound(); const { data: currentPage } = useSWRxCurrentPage(shareLinkId ?? undefined); const { data: editorMode } = useEditorMode(); const { open: openDescendantPageListModal } = useDescendantsPageListModal(); const isViewMode = editorMode === EditorMode.View; const isTopPagePath = isTopPage(currentPagePath ?? ''); const revision = currentPage?.revision; return ( <> { !isNotFound && !currentPage?.isEmpty && ( {/* Page list */} { currentPagePath != null && !isSharedUser && ( openDescendantPageListModal(currentPagePath)} > {t('page_list')} ) } {/* Comments */} {/* { getCommentListDom != null && !isTopPagePath && ( */} { !isTopPagePath && ( smoothScrollIntoView(getCommentListDom, WIKI_HEADER_LINK)} > Comments ) } {/* */} ) } { isUserPage && } {/* { !isNotFound && } */} { !isNotFound && revision != null && isPopulated(revision) && revision.body } { isNotFound && } { isEditable && ( {/* */} ) } { isEditable && ( {/* */} ) } { isEditable && !isViewMode && } { isEditable && } > ); }; export default DisplaySwitcher;