|
@@ -1,8 +1,11 @@
|
|
|
import type { FC } from 'react';
|
|
import type { FC } from 'react';
|
|
|
-import { Suspense, useState, useCallback } from 'react';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ Suspense, useState, useCallback, useEffect,
|
|
|
|
|
+} from 'react';
|
|
|
|
|
|
|
|
import nodePath from 'path';
|
|
import nodePath from 'path';
|
|
|
|
|
|
|
|
|
|
+import { pathUtils } from '@growi/core/dist/utils';
|
|
|
import { useTranslation } from 'next-i18next';
|
|
import { useTranslation } from 'next-i18next';
|
|
|
import {
|
|
import {
|
|
|
Modal, ModalHeader, ModalBody, ModalFooter, Button,
|
|
Modal, ModalHeader, ModalBody, ModalFooter, Button,
|
|
@@ -11,7 +14,7 @@ import {
|
|
|
import type { IPageForItem } from '~/interfaces/page';
|
|
import type { IPageForItem } from '~/interfaces/page';
|
|
|
import { useTargetAndAncestors, useIsGuestUser, useIsReadOnlyUser } from '~/stores/context';
|
|
import { useTargetAndAncestors, useIsGuestUser, useIsReadOnlyUser } from '~/stores/context';
|
|
|
import { usePageSelectModal } from '~/stores/modal';
|
|
import { usePageSelectModal } from '~/stores/modal';
|
|
|
-import { useCurrentPagePath, useCurrentPageId, useSWRxCurrentPage } from '~/stores/page';
|
|
|
|
|
|
|
+import { useSWRxCurrentPage } from '~/stores/page';
|
|
|
|
|
|
|
|
import { ItemsTree } from '../ItemsTree';
|
|
import { ItemsTree } from '../ItemsTree';
|
|
|
import ItemsTreeContentSkeleton from '../ItemsTree/ItemsTreeContentSkeleton';
|
|
import ItemsTreeContentSkeleton from '../ItemsTree/ItemsTreeContentSkeleton';
|
|
@@ -19,7 +22,6 @@ import { usePagePathRenameHandler } from '../PageEditor/page-path-rename-utils';
|
|
|
|
|
|
|
|
import { TreeItemForModal } from './TreeItemForModal';
|
|
import { TreeItemForModal } from './TreeItemForModal';
|
|
|
|
|
|
|
|
-
|
|
|
|
|
export const PageSelectModal: FC = () => {
|
|
export const PageSelectModal: FC = () => {
|
|
|
const {
|
|
const {
|
|
|
data: PageSelectModalData,
|
|
data: PageSelectModalData,
|
|
@@ -34,8 +36,6 @@ export const PageSelectModal: FC = () => {
|
|
|
|
|
|
|
|
const { data: isGuestUser } = useIsGuestUser();
|
|
const { data: isGuestUser } = useIsGuestUser();
|
|
|
const { data: isReadOnlyUser } = useIsReadOnlyUser();
|
|
const { data: isReadOnlyUser } = useIsReadOnlyUser();
|
|
|
- const { data: currentPath } = useCurrentPagePath();
|
|
|
|
|
- const { data: targetId } = useCurrentPageId();
|
|
|
|
|
const { data: targetAndAncestorsData } = useTargetAndAncestors();
|
|
const { data: targetAndAncestorsData } = useTargetAndAncestors();
|
|
|
const { data: currentPage } = useSWRxCurrentPage();
|
|
const { data: currentPage } = useSWRxCurrentPage();
|
|
|
|
|
|
|
@@ -45,7 +45,7 @@ export const PageSelectModal: FC = () => {
|
|
|
const parentPagePath = page.path;
|
|
const parentPagePath = page.path;
|
|
|
|
|
|
|
|
if (parentPagePath == null) {
|
|
if (parentPagePath == null) {
|
|
|
- return;
|
|
|
|
|
|
|
+ return <></>;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
setClickedParentPagePath(parentPagePath);
|
|
setClickedParentPagePath(parentPagePath);
|
|
@@ -67,12 +67,14 @@ export const PageSelectModal: FC = () => {
|
|
|
closeModal();
|
|
closeModal();
|
|
|
}, [clickedParentPagePath, closeModal, currentPage?.path, pagePathRenameHandler]);
|
|
}, [clickedParentPagePath, closeModal, currentPage?.path, pagePathRenameHandler]);
|
|
|
|
|
|
|
|
- const targetPathOrId = targetId || currentPath;
|
|
|
|
|
|
|
+ const parentPagePath = pathUtils.addTrailingSlash(nodePath.dirname(currentPage?.path ?? ''));
|
|
|
|
|
+
|
|
|
|
|
+ const targetPathOrId = clickedParentPagePath || parentPagePath;
|
|
|
|
|
|
|
|
- const path = currentPath || '/';
|
|
|
|
|
|
|
+ const targetPath = clickedParentPagePath || parentPagePath;
|
|
|
|
|
|
|
|
if (isGuestUser == null) {
|
|
if (isGuestUser == null) {
|
|
|
- return null;
|
|
|
|
|
|
|
+ return <></>;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
@@ -89,7 +91,7 @@ export const PageSelectModal: FC = () => {
|
|
|
CustomTreeItem={TreeItemForModal}
|
|
CustomTreeItem={TreeItemForModal}
|
|
|
isEnableActions={!isGuestUser}
|
|
isEnableActions={!isGuestUser}
|
|
|
isReadOnlyUser={!!isReadOnlyUser}
|
|
isReadOnlyUser={!!isReadOnlyUser}
|
|
|
- targetPath={path}
|
|
|
|
|
|
|
+ targetPath={targetPath}
|
|
|
targetPathOrId={targetPathOrId}
|
|
targetPathOrId={targetPathOrId}
|
|
|
targetAndAncestorsData={targetAndAncestorsData}
|
|
targetAndAncestorsData={targetAndAncestorsData}
|
|
|
onClickTreeItem={onClickTreeItem}
|
|
onClickTreeItem={onClickTreeItem}
|