import React, { Suspense, useCallback, useRef, type JSX, } from 'react'; import type { IPagePopulatedToShowRevision, IPageInfoForOperation } from '@growi/core'; import { pagePathUtils } from '@growi/core/dist/utils'; import { useTranslation } from 'next-i18next'; import dynamic from 'next/dynamic'; import { scroller } from 'react-scroll'; import { useIsGuestUser, useIsReadOnlyUser } from '~/states/context'; import { useShowPageSideAuthors } from '~/states/server-configurations'; import { useDescendantsPageListModal, useTagEditModal } from '~/stores/modal'; import { useSWRxPageInfo, useSWRxTagsInfo } from '~/stores/page'; import { useIsAbleToShowTagLabel } from '~/stores/ui'; import { ContentLinkButtons } from '../ContentLinkButtons'; import { PageTagsSkeleton } from '../PageTags'; import TableOfContents from '../TableOfContents'; import { PageAccessoriesControl } from './PageAccessoriesControl'; import styles from './PageSideContents.module.scss'; const { isTopPage, isUsersHomepage, isTrashPage } = pagePathUtils; const PageTags = dynamic(() => import('../PageTags').then(mod => mod.PageTags), { ssr: false, loading: PageTagsSkeleton, }); const AuthorInfo = dynamic(() => import('~/client/components/AuthorInfo').then(mod => mod.AuthorInfo), { ssr: false }); type TagsProps = { pageId: string, revisionId: string, } const Tags = (props: TagsProps): JSX.Element => { const { pageId, revisionId } = props; const { data: tagsInfoData } = useSWRxTagsInfo(pageId, { suspense: true }); const { data: showTagLabel } = useIsAbleToShowTagLabel(); const [isGuestUser] = useIsGuestUser(); const [isReadOnlyUser] = useIsReadOnlyUser(); const { open: openTagEditModal } = useTagEditModal(); const onClickEditTagsButton = useCallback(() => { if (tagsInfoData == null) { return; } openTagEditModal(tagsInfoData.tags, pageId, revisionId); }, [pageId, revisionId, tagsInfoData, openTagEditModal]); if (!showTagLabel || tagsInfoData == null) { return <>>; } const isTagLabelsDisabled = !!isGuestUser || !!isReadOnlyUser; return (