|
|
@@ -19,7 +19,6 @@ import { useSWRxCurrentPage } from '~/stores/page';
|
|
|
|
|
|
import { ItemsTree } from '../ItemsTree';
|
|
|
import ItemsTreeContentSkeleton from '../ItemsTree/ItemsTreeContentSkeleton';
|
|
|
-import { usePagePathRenameHandler } from '../PageEditor/page-path-rename-utils';
|
|
|
|
|
|
import { TreeItemForModal } from './TreeItemForModal';
|
|
|
|
|
|
@@ -32,7 +31,7 @@ export const PageSelectModal: FC = () => {
|
|
|
|
|
|
const isOpened = PageSelectModalData?.isOpened ?? false;
|
|
|
|
|
|
- const [clickedParentPagePath, setClickedParentPagePath] = useState<string | null>(null);
|
|
|
+ const [clickedParentPage, setClickedParentPage] = useState<IPageForItem | null>(null);
|
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
@@ -41,8 +40,6 @@ export const PageSelectModal: FC = () => {
|
|
|
const { data: targetAndAncestorsData } = useTargetAndAncestors();
|
|
|
const { data: currentPage } = useSWRxCurrentPage();
|
|
|
|
|
|
- const pagePathRenameHandler = usePagePathRenameHandler(currentPage);
|
|
|
-
|
|
|
const onClickTreeItem = useCallback((page: IPageForItem) => {
|
|
|
const parentPagePath = page.path;
|
|
|
|
|
|
@@ -50,30 +47,27 @@ export const PageSelectModal: FC = () => {
|
|
|
return <></>;
|
|
|
}
|
|
|
|
|
|
- setClickedParentPagePath(parentPagePath);
|
|
|
+ setClickedParentPage(page);
|
|
|
}, []);
|
|
|
|
|
|
const onClickCancel = useCallback(() => {
|
|
|
- setClickedParentPagePath(null);
|
|
|
+ setClickedParentPage(null);
|
|
|
closeModal();
|
|
|
}, [closeModal]);
|
|
|
|
|
|
const onClickDone = useCallback(() => {
|
|
|
- if (clickedParentPagePath != null) {
|
|
|
- const currentPageTitle = nodePath.basename(currentPage?.path ?? '') || '/';
|
|
|
- const newPagePath = nodePath.resolve(clickedParentPagePath, currentPageTitle);
|
|
|
-
|
|
|
- pagePathRenameHandler(newPagePath);
|
|
|
+ if (clickedParentPage != null) {
|
|
|
+ PageSelectModalData?.opts?.onSelected?.(clickedParentPage);
|
|
|
}
|
|
|
|
|
|
closeModal();
|
|
|
- }, [clickedParentPagePath, closeModal, currentPage?.path, pagePathRenameHandler]);
|
|
|
+ }, [PageSelectModalData?.opts, clickedParentPage, closeModal]);
|
|
|
|
|
|
const parentPagePath = pathUtils.addTrailingSlash(nodePath.dirname(currentPage?.path ?? ''));
|
|
|
|
|
|
- const targetPathOrId = clickedParentPagePath || parentPagePath;
|
|
|
+ const targetPathOrId = clickedParentPage?.path || parentPagePath;
|
|
|
|
|
|
- const targetPath = clickedParentPagePath || parentPagePath;
|
|
|
+ const targetPath = clickedParentPage?.path || parentPagePath;
|
|
|
|
|
|
if (isGuestUser == null) {
|
|
|
return <></>;
|