import React, { useMemo } from 'react'; import { pagePathUtils } from '@growi/core'; import { useTranslation } from 'react-i18next'; import { TabContent, TabPane } from 'reactstrap'; import { smoothScrollIntoView } from '~/client/util/smooth-scroll'; import { useCurrentPagePath, useIsSharedUser, useIsEditable, useCurrentPageId, useIsUserPage, usePageUser, } from '~/stores/context'; import { useDescendantsPageListModal } from '~/stores/modal'; import { useSWRxPageByPath } from '~/stores/page'; import { EditorMode, useEditorMode } from '~/stores/ui'; import CountBadge from '../Common/CountBadge'; import ContentLinkButtons from '../ContentLinkButtons'; import HashChanged from '../EventListeneres/HashChanged'; import PageListIcon from '../Icons/PageListIcon'; import Page from '../Page'; import Editor from '../PageEditor'; import EditorNavbarBottom from '../PageEditor/EditorNavbarBottom'; 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(); // get element for smoothScroll const getCommentListDom = useMemo(() => { return document.getElementById('page-comments-list') }, []); const { data: currentPageId } = useCurrentPageId(); const { data: currentPath } = useCurrentPagePath(); const { data: isSharedUser } = useIsSharedUser(); const { data: isUserPage } = useIsUserPage(); const { data: isEditable } = useIsEditable(); const { data: pageUser } = usePageUser(); const { data: currentPage } = useSWRxPageByPath(currentPath); const { data: editorMode } = useEditorMode(); const { open: openDescendantPageListModal } = useDescendantsPageListModal(); const isPageExist = currentPageId != null; const isViewMode = editorMode === EditorMode.View; const isTopPagePath = isTopPage(currentPath ?? ''); return ( <>
{ isPageExist && (
{/* Page list */}
{ currentPath != null && !isSharedUser && ( ) }
{/* Comments */} { getCommentListDom != null && !isTopPagePath && (
) }
) }
{ isUserPage && }
{ isEditable && (
) } { isEditable && (
) }
{ isEditable && !isViewMode && } { isEditable && } ); }; export default DisplaySwitcher;