Yuki Takei 3 лет назад
Родитель
Сommit
c147a51d21

+ 5 - 3
packages/app/src/pages/[[...path]].page.tsx

@@ -152,7 +152,7 @@ type Props = CommonProps & {
   isIdenticalPathPage?: boolean,
   isForbidden: boolean,
   isNotFound: boolean,
-  isNotCreatablePage: boolean,
+  isNotCreatable: boolean,
   // isAbleToDeleteCompletely: boolean,
 
   templateTagData?: string[],
@@ -218,6 +218,7 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
   // useOwnerOfCurrentPage(props.pageUser != null ? JSON.parse(props.pageUser) : null);
   useIsForbidden(props.isForbidden);
   useIsNotFound(props.isNotFound);
+  useIsNotCreatable(props.isNotCreatable);
   useRedirectFrom(props.redirectFrom);
   useIsSharedUser(false); // this page cann't be routed for '/share'
   useIsIdenticalPath(props.isIdenticalPathPage ?? false);
@@ -469,17 +470,18 @@ async function injectRoutingInformation(context: GetServerSidePropsContext, prop
   const page = props.pageWithMeta?.data;
 
   if (props.isIdenticalPathPage) {
-    // TBD
+    props.isNotCreatable = true;
   }
   else if (page == null) {
     props.isNotFound = true;
-    props.isNotCreatablePage = !isCreatablePage(currentPathname);
+    props.isNotCreatable = !isCreatablePage(currentPathname);
     // check the page is forbidden or just does not exist.
     const count = isPermalink ? await Page.count({ _id: pageId }) : await Page.count({ path: currentPathname });
     props.isForbidden = count > 0;
   }
   else {
     props.isNotFound = page.isEmpty;
+    props.isNotCreatable = false;
     // /62a88db47fed8b2d94f30000 ==> /path/to/page
     if (isPermalink && page.isEmpty) {
       props.currentPathname = page.path;

+ 8 - 3
packages/app/src/stores/context.tsx

@@ -56,6 +56,10 @@ export const useIsForbidden = (initialData?: boolean): SWRResponse<boolean, Erro
   return useContextSWR<boolean, Error>('isForbidden', initialData, { fallbackData: false });
 };
 
+export const useIsNotCreatable = (initialData?: boolean): SWRResponse<boolean, Error> => {
+  return useContextSWR<boolean, Error>('isNotCreatable', initialData, { fallbackData: false });
+};
+
 export const useIsNotFound = (initialData?: boolean): SWRResponse<boolean, Error> => {
   return useContextSWR<boolean, Error>('isNotFound', initialData, { fallbackData: false });
 };
@@ -230,12 +234,13 @@ export const useIsGuestUser = (): SWRResponse<boolean, Error> => {
 export const useIsEditable = (): SWRResponse<boolean, Error> => {
   const { data: isGuestUser } = useIsGuestUser();
   const { data: isForbidden } = useIsForbidden();
+  const { data: isNotCreatable } = useIsNotCreatable();
   const { data: isIdenticalPath } = useIsIdenticalPath();
 
   return useSWRImmutable(
-    ['isEditable', isGuestUser, isForbidden, isIdenticalPath],
-    (key: Key, isGuestUser: boolean, isForbidden: boolean, isIdenticalPath: boolean) => {
-      return (!isForbidden && !isIdenticalPath && !isGuestUser);
+    ['isEditable', isGuestUser, isForbidden, isNotCreatable, isIdenticalPath],
+    (key: Key, isGuestUser: boolean, isForbidden: boolean, isNotCreatable: boolean, isIdenticalPath: boolean) => {
+      return (!isForbidden && !isIdenticalPath && !isNotCreatable && !isGuestUser);
     },
   );
 };

+ 1 - 1
packages/app/src/stores/ui.tsx

@@ -473,7 +473,7 @@ export const useIsAbleToShowPageEditorModeManager = (): SWRResponse<boolean, Err
   const includesUndefined = [isEditable, isSharedUser].some(v => v === undefined);
 
   return useSWRImmutable(
-    includesUndefined ? null : key,
+    includesUndefined ? null : [key, isEditable, isSharedUser],
     () => !!isEditable && !isSharedUser,
   );
 };