import React, { useMemo } from 'react'; import { pagePathUtils } from '@growi/core'; import { useTranslation } from 'next-i18next'; import dynamic from 'next/dynamic'; import { Link } from 'react-scroll'; import { DEFAULT_AUTO_SCROLL_OPTS } from '~/client/util/smooth-scroll'; import { useCurrentPagePath, useIsSharedUser, useIsEditable, 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 { ContentLinkButtonsProps } from '../ContentLinkButtons'; import CustomTabContent from '../CustomNavigation/CustomTabContent'; import PageListIcon from '../Icons/PageListIcon'; import { Page } from '../Page'; import TableOfContents from '../TableOfContents'; import { UserInfoProps } from '../User/UserInfo'; import styles from './DisplaySwitcher.module.scss'; const { isTopPage, isUsersHomePage } = pagePathUtils; const PageEditor = dynamic(() => import('../PageEditor'), { ssr: false }); const PageEditorByHackmd = dynamic(() => import('../PageEditorByHackmd').then(mod => mod.PageEditorByHackmd), { ssr: false }); const EditorNavbarBottom = dynamic(() => import('../PageEditor/EditorNavbarBottom'), { ssr: false }); const HashChanged = dynamic(() => import('../EventListeneres/HashChanged'), { ssr: false }); const ContentLinkButtons = dynamic(() => import('../ContentLinkButtons').then(mod => mod.ContentLinkButtons), { ssr: false }); const NotFoundPage = dynamic(() => import('../NotFoundPage'), { ssr: false }); const UserInfo = dynamic(() => import('../User/UserInfo').then(mod => mod.UserInfo), { ssr: false }); const PageView = React.memo((): JSX.Element => { const { t } = useTranslation(); const { data: currentPagePath } = useCurrentPagePath(); const { data: isSharedUser } = useIsSharedUser(); const { data: shareLinkId } = useShareLinkId(); const { data: isNotFound } = useIsNotFound(); const { data: currentPage } = useSWRxCurrentPage(shareLinkId ?? undefined); const { open: openDescendantPageListModal } = useDescendantsPageListModal(); const isTopPagePath = isTopPage(currentPagePath ?? ''); const isUsersHomePagePath = isUsersHomePage(currentPagePath ?? ''); return (
{ isUsersHomePagePath && } { !isNotFound && } { isNotFound && }
{ !isNotFound && (
{/* Page list */}
{ currentPagePath != null && !isSharedUser && ( ) }
{/* Comments */} { !isTopPagePath && (
) }
{ isUsersHomePagePath && }
) }
); }); PageView.displayName = 'PageView'; const DisplaySwitcher = React.memo((): JSX.Element => { const { data: isEditable } = useIsEditable(); const { data: editorMode = EditorMode.View } = useEditorMode(); const isViewMode = editorMode === EditorMode.View; const navTabMapping = useMemo(() => { return { [EditorMode.View]: { Content: () => (
), }, [EditorMode.Editor]: { Content: () => ( isEditable ? (
) : <> ), }, [EditorMode.HackMD]: { Content: () => ( isEditable ? (
) : <> ), }, }; }, [isEditable]); return ( <> { isEditable && !isViewMode && } { isEditable && } ); }); DisplaySwitcher.displayName = 'DisplaySwitcher'; export default DisplaySwitcher;