|
|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useCallback } from 'react';
|
|
|
+import React, { useState, useCallback } from 'react';
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
@@ -10,10 +10,11 @@ import EditorContainer from '~/client/services/EditorContainer';
|
|
|
import {
|
|
|
EditorMode, useDrawerMode, useEditorMode, useIsDeviceSmallerThanMd, useIsAbleToShowPageManagement, useIsAbleToShowTagLabel,
|
|
|
useIsAbleToShowPageEditorModeManager, useIsAbleToShowPageAuthors, usePageAccessoriesModal, PageAccessoriesModalContents,
|
|
|
+ usePageDuplicateModalStatus, usePageRenameModalStatus, usePageDeleteModal,
|
|
|
} from '~/stores/ui';
|
|
|
import {
|
|
|
useCurrentCreatedAt, useCurrentUpdatedAt, useCurrentPageId, useRevisionId, useCurrentPagePath,
|
|
|
- useCreator, useRevisionAuthor, useIsGuestUser, useIsSharedUser, useShareLinkId,
|
|
|
+ useCreator, useRevisionAuthor, useCurrentUser, useIsGuestUser, useIsSharedUser, useShareLinkId,
|
|
|
} from '~/stores/context';
|
|
|
import { useSWRTagsInfo } from '~/stores/page';
|
|
|
|
|
|
@@ -30,6 +31,7 @@ import { SubNavButtons } from './SubNavButtons';
|
|
|
import PageEditorModeManager from './PageEditorModeManager';
|
|
|
import { GrowiSubNavigation } from './GrowiSubNavigation';
|
|
|
import PresentationIcon from '../Icons/PresentationIcon';
|
|
|
+import CreateTemplateModal from '../CreateTemplateModal';
|
|
|
import { exportAsMarkdown } from '~/client/services/page-operation';
|
|
|
|
|
|
|
|
|
@@ -37,12 +39,20 @@ type AdditionalMenuItemsProps = AdditionalMenuItemsRendererProps & {
|
|
|
pageId: string,
|
|
|
revisionId: string,
|
|
|
isLinkSharingDisabled?: boolean,
|
|
|
+ onClickTemplateMenuItem: (isPageTemplateModalShown: boolean) => void,
|
|
|
+
|
|
|
}
|
|
|
|
|
|
const AdditionalMenuItems = (props: AdditionalMenuItemsProps): JSX.Element => {
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
- const { pageId, revisionId, isLinkSharingDisabled } = props;
|
|
|
+ const {
|
|
|
+ pageId, revisionId, isLinkSharingDisabled, onClickTemplateMenuItem,
|
|
|
+ } = props;
|
|
|
+
|
|
|
+ const openPageTemplateModalHandler = () => {
|
|
|
+ onClickTemplateMenuItem(true);
|
|
|
+ };
|
|
|
|
|
|
const { data: isGuestUser } = useIsGuestUser();
|
|
|
const { data: isSharedUser } = useIsSharedUser();
|
|
|
@@ -95,7 +105,7 @@ const AdditionalMenuItems = (props: AdditionalMenuItemsProps): JSX.Element => {
|
|
|
<DropdownItem divider />
|
|
|
|
|
|
{/* Create template */}
|
|
|
- <DropdownItem onClick={() => { /* TODO: implement in https://redmine.weseek.co.jp/issues/87673 */ }}>
|
|
|
+ <DropdownItem onClick={openPageTemplateModalHandler}>
|
|
|
<i className="icon-fw icon-magic-wand"></i> { t('template.option_label.create/edit') }
|
|
|
</DropdownItem>
|
|
|
</>
|
|
|
@@ -114,6 +124,7 @@ const GrowiContextualSubNavigation = (props) => {
|
|
|
const { data: path } = useCurrentPagePath();
|
|
|
const { data: creator } = useCreator();
|
|
|
const { data: revisionAuthor } = useRevisionAuthor();
|
|
|
+ const { data: currentUser } = useCurrentUser();
|
|
|
const { data: isGuestUser } = useIsGuestUser();
|
|
|
const { data: isSharedUser } = useIsSharedUser();
|
|
|
const { data: shareLinkId } = useShareLinkId();
|
|
|
@@ -125,6 +136,12 @@ const GrowiContextualSubNavigation = (props) => {
|
|
|
|
|
|
const { mutate: mutateSWRTagsInfo, data: tagsInfoData } = useSWRTagsInfo(pageId);
|
|
|
|
|
|
+ const { open: openDuplicateModal } = usePageDuplicateModalStatus();
|
|
|
+ const { open: openRenameModal } = usePageRenameModalStatus();
|
|
|
+ const { open: openDeleteModal } = usePageDeleteModal();
|
|
|
+
|
|
|
+ const [isPageTemplateModalShown, setIsPageTempleteModalShown] = useState(false);
|
|
|
+
|
|
|
const {
|
|
|
editorContainer, isCompactMode, isLinkSharingDisabled,
|
|
|
} = props;
|
|
|
@@ -153,6 +170,23 @@ const GrowiContextualSubNavigation = (props) => {
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
}, [pageId]);
|
|
|
|
|
|
+ const duplicateItemClickedHandler = useCallback(async(pageId, path) => {
|
|
|
+ openDuplicateModal(pageId, path);
|
|
|
+ }, [openDuplicateModal]);
|
|
|
+
|
|
|
+ const renameItemClickedHandler = useCallback(async(pageId, revisionId, path) => {
|
|
|
+ openRenameModal(pageId, revisionId, path);
|
|
|
+ }, [openRenameModal]);
|
|
|
+
|
|
|
+ const deleteItemClickedHandler = useCallback(async(pageToDelete) => {
|
|
|
+ openDeleteModal([pageToDelete]);
|
|
|
+ }, [openDeleteModal]);
|
|
|
+
|
|
|
+ const templateMenuItemClickHandler = useCallback(() => {
|
|
|
+ setIsPageTempleteModalShown(true);
|
|
|
+ }, []);
|
|
|
+
|
|
|
+
|
|
|
const ControlComponents = useCallback(() => {
|
|
|
function onPageEditorModeButtonClicked(viewType) {
|
|
|
mutateEditorMode(viewType);
|
|
|
@@ -167,11 +201,21 @@ const GrowiContextualSubNavigation = (props) => {
|
|
|
pageId={pageId}
|
|
|
shareLinkId={shareLinkId}
|
|
|
revisionId={revisionId}
|
|
|
+ path={path}
|
|
|
disableSeenUserInfoPopover={isSharedUser}
|
|
|
showPageControlDropdown={isAbleToShowPageManagement}
|
|
|
additionalMenuItemRenderer={props => (
|
|
|
- <AdditionalMenuItems {...props} pageId={pageId} revisionId={revisionId} isLinkSharingDisabled={isLinkSharingDisabled} />
|
|
|
+ <AdditionalMenuItems
|
|
|
+ {...props}
|
|
|
+ pageId={pageId}
|
|
|
+ revisionId={revisionId}
|
|
|
+ isLinkSharingDisabled={isLinkSharingDisabled}
|
|
|
+ onClickTemplateMenuItem={templateMenuItemClickHandler}
|
|
|
+ />
|
|
|
)}
|
|
|
+ onClickDuplicateMenuItem={duplicateItemClickedHandler}
|
|
|
+ onClickRenameMenuItem={renameItemClickedHandler}
|
|
|
+ onClickDeleteMenuItem={deleteItemClickedHandler}
|
|
|
/>
|
|
|
) }
|
|
|
</div>
|
|
|
@@ -185,14 +229,21 @@ const GrowiContextualSubNavigation = (props) => {
|
|
|
/>
|
|
|
)}
|
|
|
</div>
|
|
|
+ {currentUser != null && (
|
|
|
+ <CreateTemplateModal
|
|
|
+ path={path}
|
|
|
+ isOpen={isPageTemplateModalShown}
|
|
|
+ onClose={() => setIsPageTempleteModalShown(false)}
|
|
|
+ />
|
|
|
+ )}
|
|
|
</>
|
|
|
);
|
|
|
}, [
|
|
|
- pageId, revisionId, shareLinkId,
|
|
|
- editorMode, mutateEditorMode,
|
|
|
- isCompactMode, isLinkSharingDisabled,
|
|
|
- isDeviceSmallerThanMd, isGuestUser, isSharedUser,
|
|
|
+ pageId, revisionId, shareLinkId, editorMode, mutateEditorMode, isCompactMode,
|
|
|
+ isLinkSharingDisabled, isDeviceSmallerThanMd, isGuestUser, isSharedUser, currentUser,
|
|
|
isViewMode, isAbleToShowPageEditorModeManager, isAbleToShowPageManagement,
|
|
|
+ duplicateItemClickedHandler, renameItemClickedHandler, deleteItemClickedHandler,
|
|
|
+ path, templateMenuItemClickHandler, isPageTemplateModalShown,
|
|
|
]);
|
|
|
|
|
|
|