|
|
@@ -12,9 +12,8 @@ import { useRouter } from 'next/router';
|
|
|
import { DropdownItem } from 'reactstrap';
|
|
|
|
|
|
import {
|
|
|
- createPage, exist, exportAsMarkdown, updateContentWidth,
|
|
|
+ exportAsMarkdown, updateContentWidth,
|
|
|
} from '~/client/services/page-operation';
|
|
|
-import { toastError } from '~/client/util/toastr';
|
|
|
import type { OnDuplicatedFunction, OnRenamedFunction, OnDeletedFunction } from '~/interfaces/ui';
|
|
|
import {
|
|
|
useCurrentPathname,
|
|
|
@@ -33,7 +32,6 @@ import {
|
|
|
useIsAbleToChangeEditorMode,
|
|
|
useSelectedGrant,
|
|
|
} from '~/stores/ui';
|
|
|
-import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
import CreateTemplateModal from '../CreateTemplateModal';
|
|
|
import AttachmentIcon from '../Icons/AttachmentIcon';
|
|
|
@@ -179,16 +177,12 @@ type GrowiContextualSubNavigationProps = {
|
|
|
isLinkSharingDisabled?: boolean,
|
|
|
};
|
|
|
|
|
|
-const logger = loggerFactory('growi:cli:GrowiContextualSubNavigation');
|
|
|
-
|
|
|
const GrowiContextualSubNavigation = (props: GrowiContextualSubNavigationProps): JSX.Element => {
|
|
|
|
|
|
const { currentPage } = props;
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
- const [isCreating, setIsCreating] = useState<boolean>(false);
|
|
|
-
|
|
|
const { data: shareLinkId } = useShareLinkId();
|
|
|
const { trigger: mutateCurrentPage } = useSWRMUTxCurrentPage();
|
|
|
|
|
|
@@ -269,68 +263,6 @@ const GrowiContextualSubNavigation = (props: GrowiContextualSubNavigationProps):
|
|
|
}
|
|
|
}, [isSharedPage, mutateCurrentPage]);
|
|
|
|
|
|
- const onClickTemplateForChildrenButtonHandler = useCallback(async() => {
|
|
|
- try {
|
|
|
- setIsCreating(true);
|
|
|
-
|
|
|
- const path = currentPage == null || currentPage.path === '/'
|
|
|
- ? '/_template'
|
|
|
- : `${currentPage.path}/_template`;
|
|
|
-
|
|
|
- const params = {
|
|
|
- isSlackEnabled: false,
|
|
|
- slackChannels: '',
|
|
|
- grant: currentPage?.grant || 1,
|
|
|
- grantUserGroupId: currentPage?.grantedGroup?._id,
|
|
|
- };
|
|
|
-
|
|
|
- const res = await exist(JSON.stringify([path]));
|
|
|
- if (!res.pages[path]) {
|
|
|
- await createPage(path, '', params);
|
|
|
- }
|
|
|
-
|
|
|
- router.push(`${path}#edit`);
|
|
|
- }
|
|
|
- catch (err) {
|
|
|
- logger.warn(err);
|
|
|
- toastError(err);
|
|
|
- }
|
|
|
- finally {
|
|
|
- setIsCreating(false);
|
|
|
- }
|
|
|
- }, [currentPage, router]);
|
|
|
-
|
|
|
- const onClickTemplateForDescendantsButtonHandler = useCallback(async() => {
|
|
|
- try {
|
|
|
- setIsCreating(true);
|
|
|
-
|
|
|
- const path = currentPage == null || currentPage.path === '/'
|
|
|
- ? '/__template'
|
|
|
- : `${currentPage.path}/__template`;
|
|
|
-
|
|
|
- const params = {
|
|
|
- isSlackEnabled: false,
|
|
|
- slackChannels: '',
|
|
|
- grant: currentPage?.grant || 1,
|
|
|
- grantUserGroupId: currentPage?.grantedGroup?._id,
|
|
|
- };
|
|
|
-
|
|
|
- const res = await exist(JSON.stringify([path]));
|
|
|
- if (!res.pages[path]) {
|
|
|
- await createPage(path, '', params);
|
|
|
- }
|
|
|
-
|
|
|
- router.push(`${path}#edit`);
|
|
|
- }
|
|
|
- catch (err) {
|
|
|
- logger.warn(err);
|
|
|
- toastError(err);
|
|
|
- }
|
|
|
- finally {
|
|
|
- setIsCreating(false);
|
|
|
- }
|
|
|
- }, [currentPage, router]);
|
|
|
-
|
|
|
const additionalMenuItemsRenderer = useCallback(() => {
|
|
|
if (revisionId == null || pageId == null) {
|
|
|
return (
|
|
|
@@ -406,9 +338,6 @@ const GrowiContextualSubNavigation = (props: GrowiContextualSubNavigationProps):
|
|
|
path={path}
|
|
|
isOpen={isPageTemplateModalShown}
|
|
|
onClose={() => setIsPageTempleteModalShown(false)}
|
|
|
- isCreating={isCreating}
|
|
|
- onClickTemplateForChildrenButtonHandler={onClickTemplateForChildrenButtonHandler}
|
|
|
- onClickTemplateForDescendantsButtonHandler={onClickTemplateForDescendantsButtonHandler}
|
|
|
/>
|
|
|
)}
|
|
|
</>
|