Sfoglia il codice sorgente

use nonEmptyClosestAncestor for today's memo parentPath

Futa Arai 1 anno fa
parent
commit
e5822fcea6

+ 5 - 13
apps/app/src/client/services/create-page/use-create-page-and-transit.tsx

@@ -111,19 +111,11 @@ export const useCreatePageAndTransit: UseCreatePageAndTransit = () => {
 
 
     // If parent page is granted to non-user-related groups, let the user select whether or not to inherit them.
     // If parent page is granted to non-user-related groups, let the user select whether or not to inherit them.
     if (params.parentPath != null) {
     if (params.parentPath != null) {
-      try {
-        const { isNonUserRelatedGroupsGranted } = await getIsNonUserRelatedGroupsGranted(params.parentPath);
-        if (isNonUserRelatedGroupsGranted) {
-          // create and transit request will be made from modal
-          openGrantedGroupsInheritanceSelectModal(_createAndTransit);
-          return;
-        }
-      }
-      catch (err) {
-        // Do not throw error when the parent page is empty, since empty parent page could be created on create request
-        if (err[0]?.code !== 'page_unreachable_or_empty') {
-          throw err;
-        }
+      const { isNonUserRelatedGroupsGranted } = await getIsNonUserRelatedGroupsGranted(params.parentPath);
+      if (isNonUserRelatedGroupsGranted) {
+        // create and transit request will be made from modal
+        openGrantedGroupsInheritanceSelectModal(_createAndTransit);
+        return;
       }
       }
     }
     }
 
 

+ 4 - 1
apps/app/src/components/PageCreateModal.tsx

@@ -14,6 +14,7 @@ import { debounce } from 'throttle-debounce';
 import { useCreateTemplatePage } from '~/client/services/create-page';
 import { useCreateTemplatePage } from '~/client/services/create-page';
 import { useCreatePageAndTransit } from '~/client/services/create-page/use-create-page-and-transit';
 import { useCreatePageAndTransit } from '~/client/services/create-page/use-create-page-and-transit';
 import { useToastrOnError } from '~/client/services/use-toastr-on-error';
 import { useToastrOnError } from '~/client/services/use-toastr-on-error';
+import { apiv3Get } from '~/client/util/apiv3-client';
 import { useCurrentUser, useIsSearchServiceReachable } from '~/stores/context';
 import { useCurrentUser, useIsSearchServiceReachable } from '~/stores/context';
 import { usePageCreateModal } from '~/stores/modal';
 import { usePageCreateModal } from '~/stores/modal';
 
 
@@ -94,9 +95,11 @@ const PageCreateModal: React.FC = () => {
    */
    */
   const createTodayPage = useCallback(async() => {
   const createTodayPage = useCallback(async() => {
     const joinedPath = [todaysParentPath, todayInput].join('/');
     const joinedPath = [todaysParentPath, todayInput].join('/');
+    const res = await apiv3Get('/page/non-empty-closest-ancestor', { path: joinedPath });
+    const parentPath = res.data.nonEmptyClosestAncestor?.path;
     return createAndTransit(
     return createAndTransit(
       {
       {
-        path: joinedPath, parentPath: todaysParentPath, wip: true, origin: Origin.View,
+        path: joinedPath, parentPath, wip: true, origin: Origin.View,
       },
       },
       { shouldCheckPageExists: true, onTerminated: closeCreateModal },
       { shouldCheckPageExists: true, onTerminated: closeCreateModal },
     );
     );

+ 6 - 3
apps/app/src/components/Sidebar/PageCreateButton/hooks/use-create-todays-memo.tsx

@@ -6,6 +6,7 @@ import { format } from 'date-fns/format';
 import { useTranslation } from 'react-i18next';
 import { useTranslation } from 'react-i18next';
 
 
 import { useCreatePageAndTransit } from '~/client/services/create-page';
 import { useCreatePageAndTransit } from '~/client/services/create-page';
+import { apiv3Get } from '~/client/util/apiv3-client';
 import { useCurrentUser } from '~/stores/context';
 import { useCurrentUser } from '~/stores/context';
 
 
 
 
@@ -25,21 +26,23 @@ export const useCreateTodaysMemo: UseCreateTodaysMemo = () => {
 
 
   const parentDirName = t('create_page_dropdown.todays.memo');
   const parentDirName = t('create_page_dropdown.todays.memo');
   const now = format(new Date(), 'yyyy/MM/dd');
   const now = format(new Date(), 'yyyy/MM/dd');
-  const parentPath = `${userHomepagePath(currentUser)}/${parentDirName}`;
   const todaysPath = isCreatable
   const todaysPath = isCreatable
-    ? `${parentPath}/${now}`
+    ? `${userHomepagePath(currentUser)}/${parentDirName}/${now}`
     : null;
     : null;
 
 
   const createTodaysMemo = useCallback(async() => {
   const createTodaysMemo = useCallback(async() => {
     if (!isCreatable || todaysPath == null) return;
     if (!isCreatable || todaysPath == null) return;
 
 
+    const res = await apiv3Get('/page/non-empty-closest-ancestor', { path: todaysPath });
+    const parentPath = res.data.nonEmptyClosestAncestor?.path;
+
     return createAndTransit(
     return createAndTransit(
       {
       {
         path: todaysPath, parentPath, wip: true, origin: Origin.View,
         path: todaysPath, parentPath, wip: true, origin: Origin.View,
       },
       },
       { shouldCheckPageExists: true },
       { shouldCheckPageExists: true },
     );
     );
-  }, [createAndTransit, isCreatable, todaysPath, parentPath]);
+  }, [createAndTransit, isCreatable, todaysPath]);
 
 
   return {
   return {
     isCreating,
     isCreating,