import React, { useCallback } from 'react'; import PropTypes from 'prop-types'; import { withUnstatedContainers } from '../UnstatedUtils'; import EditorContainer from '~/client/services/EditorContainer'; import { EditorMode, useDrawerMode, useEditorMode, useIsDeviceSmallerThanMd, useIsAbleToShowPageManagement, useIsAbleToShowTagLabel, useIsAbleToShowPageEditorModeManager, useIsAbleToShowPageAuthors, } from '~/stores/ui'; import { useCurrentCreatedAt, useCurrentUpdatedAt, useCurrentPageId, useRevisionId, useCurrentPagePath, useIsDeletable, useIsAbleToDeleteCompletely, useCreator, useRevisionAuthor, useIsPageExist, useIsGuestUser, } from '~/stores/context'; import { useSWRTagsInfo } from '~/stores/page'; import TagLabels from '../Page/TagLabels'; import SubNavButtons from './SubNavButtons'; import PageEditorModeManager from './PageEditorModeManager'; import AuthorInfo from './AuthorInfo'; import DrawerToggler from './DrawerToggler'; import PagePathNav from '../PagePathNav'; import { toastSuccess, toastError } from '~/client/util/apiNotification'; import { apiPost } from '~/client/util/apiv1-client'; const GrowiSubNavigation = (props) => { const { data: isDeviceSmallerThanMd } = useIsDeviceSmallerThanMd(); const { data: isDrawerMode } = useDrawerMode(); const { data: editorMode, mutate: mutateEditorMode } = useEditorMode(); const { data: createdAt } = useCurrentCreatedAt(); const { data: updatedAt } = useCurrentUpdatedAt(); const { data: pageId } = useCurrentPageId(); const { data: revisionId } = useRevisionId(); const { data: path } = useCurrentPagePath(); const { data: isDeletable } = useIsDeletable(); const { data: isAbleToDeleteCompletely } = useIsAbleToDeleteCompletely(); const { data: creator } = useCreator(); const { data: revisionAuthor } = useRevisionAuthor(); const { data: isGuestUser } = useIsGuestUser(); const { data: isAbleToShowPageManagement } = useIsAbleToShowPageManagement(); const { data: isAbleToShowTagLabel } = useIsAbleToShowTagLabel(); const { data: isAbleToShowPageEditorModeManager } = useIsAbleToShowPageEditorModeManager(); const { data: isAbleToShowPageAuthors } = useIsAbleToShowPageAuthors(); const { mutate: mutateSWRTagsInfo, data: TagsInfoData } = useSWRTagsInfo(pageId); const { editorContainer, isCompactMode, } = props; const isViewMode = editorMode === EditorMode.View; const isEditorMode = !isViewMode; function onPageEditorModeButtonClicked(viewType) { mutateEditorMode(viewType); } const tagsUpdatedHandler = useCallback(async(newTags) => { // It will not be reflected in the DB until the page is refreshed if (editorMode === 'edit') { return editorContainer.setState({ tags: newTags }); } try { const { tags } = await apiPost('/tags.update', { pageId, revisionId, tags: newTags }); // revalidate SWRTagsInfo mutateSWRTagsInfo(); // update editorContainer.state editorContainer.setState({ tags }); toastSuccess('updated tags successfully'); } catch (err) { toastError(err, 'fail to update tags'); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [pageId]); return (