فهرست منبع

required path to create pages

kaori 3 سال پیش
والد
کامیت
03df02fa03
2فایلهای تغییر یافته به همراه10 افزوده شده و 5 حذف شده
  1. 3 2
      packages/app/src/client/services/page-operation.ts
  2. 7 3
      packages/app/src/components/PageEditor.tsx

+ 3 - 2
packages/app/src/client/services/page-operation.ts

@@ -97,7 +97,8 @@ export const resumeRenameOperation = async(pageId: string): Promise<void> => {
 };
 };
 
 
 
 
-export const createPage = async(pagePath, markdown, tmpParams): Promise<any> => {
+export const createPage = async(pagePath: string, markdown: string, tmpParams): Promise<any> => {
+  console.log('createPage', { pagePath, markdown, tmpParams });
   // clone
   // clone
   const params = Object.assign(tmpParams, {
   const params = Object.assign(tmpParams, {
     path: pagePath,
     path: pagePath,
@@ -127,7 +128,7 @@ export const updatePage = async(pageId: string, revisionId: string, markdown: st
 
 
 type PageInfo= {
 type PageInfo= {
   pageId: string | null | undefined,
   pageId: string | null | undefined,
-  path: string | null | undefined,
+  path: string,
   revisionId: string | null | undefined,
   revisionId: string | null | undefined,
 }
 }
 
 

+ 7 - 3
packages/app/src/components/PageEditor.tsx

@@ -15,7 +15,7 @@ import { saveAndReload } from '~/client/services/page-operation';
 import { apiGet, apiPostForm } from '~/client/util/apiv1-client';
 import { apiGet, apiPostForm } from '~/client/util/apiv1-client';
 import { getOptionsToSave } from '~/client/util/editor';
 import { getOptionsToSave } from '~/client/util/editor';
 import {
 import {
-  useIsEditable, useIsIndentSizeForced, useCurrentPagePath, useCurrentPageId, useIsUploadableFile, useIsUploadableImage,
+  useIsEditable, useIsIndentSizeForced, useCurrentPagePath, useCurrentPathname, useCurrentPageId, useIsUploadableFile, useIsUploadableImage,
 } from '~/stores/context';
 } from '~/stores/context';
 import {
 import {
   useCurrentIndentSize, useSWRxSlackChannels, useIsSlackEnabled, useIsTextlintEnabled, usePageTagsForEditors,
   useCurrentIndentSize, useSWRxSlackChannels, useIsSlackEnabled, useIsTextlintEnabled, usePageTagsForEditors,
@@ -92,6 +92,7 @@ const PageEditor = (props: Props): JSX.Element => {
   const { data: pageId } = useCurrentPageId();
   const { data: pageId } = useCurrentPageId();
   const { data: pageTags } = usePageTagsForEditors(pageId);
   const { data: pageTags } = usePageTagsForEditors(pageId);
   const { data: currentPagePath } = useCurrentPagePath();
   const { data: currentPagePath } = useCurrentPagePath();
+  const { data: currentPathname } = useCurrentPathname();
   const { data: slackChannelsData } = useSWRxSlackChannels(currentPagePath);
   const { data: slackChannelsData } = useSWRxSlackChannels(currentPagePath);
   const { data: grantData, mutate: mutateGrant } = useSelectedGrant();
   const { data: grantData, mutate: mutateGrant } = useSelectedGrant();
   const { data: isTextlintEnabled } = useIsTextlintEnabled();
   const { data: isTextlintEnabled } = useIsTextlintEnabled();
@@ -316,6 +317,8 @@ const PageEditor = (props: Props): JSX.Element => {
   }, []);
   }, []);
   const scrollEditorByPreviewScrollWithThrottle = useMemo(() => throttle(20, scrollEditorByPreviewScroll), [scrollEditorByPreviewScroll]);
   const scrollEditorByPreviewScrollWithThrottle = useMemo(() => throttle(20, scrollEditorByPreviewScroll), [scrollEditorByPreviewScroll]);
 
 
+  console.log({ currentPagePath });
+
 
 
   // initial caret line
   // initial caret line
   useEffect(() => {
   useEffect(() => {
@@ -351,7 +354,7 @@ const PageEditor = (props: Props): JSX.Element => {
     const grant = grantData?.grant;
     const grant = grantData?.grant;
     const grantedGroup = grantData?.grantedGroup;
     const grantedGroup = grantData?.grantedGroup;
 
 
-    if (isSlackEnabled == null) {
+    if (isSlackEnabled == null || currentPathname == null) {
       return;
       return;
     }
     }
 
 
@@ -368,9 +371,10 @@ const PageEditor = (props: Props): JSX.Element => {
       optionsToSave = currentOptionsToSave;
       optionsToSave = currentOptionsToSave;
     }
     }
 
 
-    await saveAndReload(optionsToSave, { pageId, path: currentPagePath, revisionId: currentPage?.revision._id }, markdown);
+    await saveAndReload(optionsToSave, { pageId, path: currentPagePath || currentPathname, revisionId: currentPage?.revision._id }, markdown);
   }, [currentPage?.revision._id,
   }, [currentPage?.revision._id,
       currentPagePath,
       currentPagePath,
+      currentPathname,
       editorMode,
       editorMode,
       grantData?.grant,
       grantData?.grant,
       grantData?.grantedGroup,
       grantData?.grantedGroup,